Given Tabels A, B, C:
Attributes table A: A_ID
Attributes table B: B_ID A_ID --> Foreign Key C_ID --> Foreign Key
Attributes table C: C_ID A_ID --> Foreign Key
JPA Entities implementation: There is a bidirectional Relation between class B and A. The relation betwenn Class C and A is not mapped. There is only a @Column("A_ID") annotation in C on the "A- Attribute"
Task: Here is the insert/update order, how I am calling the entity manager.
1. Persist on entity representing table C (FK A_ID) not yet set in this table 2. Setting C_ID in Entity representing table B 3. Persist on entity representing table A. Because of a cascade there is a new insert on table B 4. Setting A_ID in entity for table B 5. Merge on entity for table C
This always ends in a foreign key constraint exception because hibernate creates the Update (Nr. 3) after the insert on table C (Nr. 1)
Why does it does not follow the order how I am calling the entity manager ?
|