-->
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.  [ 4 posts ] 
Author Message
 Post subject: Operation priorities inside Hibernate Transaction
PostPosted: Thu Sep 08, 2005 9:48 am 
Newbie

Joined: Thu Sep 08, 2005 9:27 am
Posts: 10
Hibernate version:2.1.8

Exception:
net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

Database: MySQL 4

I have a problem that could be solved if I could give a certain priority to each operation executed during the Batch Update when commiting the transacton.

The problem is that certain table rows have to be deleted before inserting new ones due to foreign key restrictions. Both deletion and creation of new objects are executed during the same hibernate transaction but when commiting hibernate tries to insert the new rows first.

In other contexts, when the new rows inserted do not violate the constraint, everything works perfectly, because old objects (rows) are deleted at the end of the sql batch update.

To make matters worse, I cannot separate these two operations in two different transactions, because data consistency would be at risk.

_________________
Pablo N. Alvarez
Austral University
Argentina


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 10:17 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
is there a way to create the delete statements before the insert statements (or create a bunch of Query classes and wait to use them) and use them at the end and do a transaction.flush() after running the delete statements but before running the insert statements.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:07 am 
Newbie

Joined: Thu Sep 08, 2005 9:27 am
Posts: 10
apparently there was no need to complicate things that much.
I hadnĀ“t thought about the flush() call in the middle of the Transaction, and that seems to have solved the problem.
What Im concerned about now is the consistency issue...

Thanks a lot!

_________________
Pablo N. Alvarez
Austral University
Argentina


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:26 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
haha, guess I got carried away with the explanation. I tend to ramble.

Well I don't know how complicated your database and its relationships are, but flush is a relatively good command so long as your cascade and delete options are correct.

Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.