-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Insert/Update executed in wrong order
PostPosted: Thu Jul 01, 2010 7:56 am 
Newbie

Joined: Tue Sep 09, 2008 11:35 am
Posts: 10
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 ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.