In JPA, having a many-to-one as primary key throws referential integrity constraint violation
问题 I have defined the following entities: @Entity public class Child implements Serializable { @Id @ManyToOne(cascade = CascadeType.ALL) public Parent parent; @Id public int id; } @Entity public class Parent { @Id public int id; } When I try to persist a Child with the following code: Parent p = new Parent(); p.id = 1; Child c1 = new Child(); c1.id = 1; c1.parent = p; em.persist(c1); Hibernate throws a 'Referential integrity constraint violation' error: Caused by: org.h2.jdbc.JdbcSQLException: