em.persist(p);
em.persist(c1);
UPDATE
I think the problem is that your code is not JPA compliant. Try with embeddedId, it works for me.
@Embeddable
public class ChildPK implements Serializable {
private int parentId;
private int childId;
// getters and setters
}
@Entity
public class Child implements Serializable {
@EmbeddedId
public ChildPK id = new ChildPK();
@MapsId( "parentId" )
@ManyToOne
public Parent parent;
}
Parent p = new Parent();
p.id = 1;
Child c1 = new Child();
c1.id.setChildId( 1 );
c1.parent = p;
em.persist( c1 );
I think it works with @IdClass
too, but I never used it.