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.  [ 3 posts ] 
Author Message
 Post subject: Insert and Updates with a trigger
PostPosted: Thu Sep 15, 2011 5:29 pm 
Newbie

Joined: Thu Sep 15, 2011 3:04 pm
Posts: 2
Hi!

We have a problem inserting and updating 2 entities (in same transaction) when a trigger is attached on a table of one of those entities table.

This is the scenario:

entityADao.save(entA); //---> entity is on database and entA has that id. So it produce an update
entityBDao.save(entB); //----> entity is not on database. So it produce an insert
//Trigger on insert or update or delete on entB table update some values of entA table

Then the hibernate log is this:
1) insert into ENTB...
2) update ENTA....

So trigger is executed on step 1 (updating ENTA table), then step 2 overwrite the updates values of the trigger.

The relation between entA and entB is entaA 1------0..N entB

So why the statements are inverted when hibernate make the queries? Is there a way to surround this problem?

The only approach that came to my mind is to fetch between step 1 and step 2.

Thanks,
Francisco.


Top
 Profile  
 
 Post subject: Re: Insert and Updates with a trigger
PostPosted: Fri Sep 16, 2011 2:09 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The order that Hibernate executes the SQL statements are documented here: http://docs.jboss.org/hibernate/core/3. ... e-flushing

The solution to your problem is to explicitly call flush() before entB is saved.


Top
 Profile  
 
 Post subject: Re: Insert and Updates with a trigger
PostPosted: Fri Sep 16, 2011 9:37 am 
Newbie

Joined: Thu Sep 15, 2011 3:04 pm
Posts: 2
When I said fetch I mean flush.

Thanks for you reply. It was very helpful.


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

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.