-->
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.  [ 2 posts ] 
Author Message
 Post subject: ConstraintViolationException
PostPosted: Thu Feb 16, 2006 6:56 pm 
Newbie

Joined: Thu Feb 16, 2006 5:46 pm
Posts: 1
I am having a problem with duplicate entry handling using hibernate in a web application.


Scenario:
I am running a batch process which does a sequence of Hibernate insert and update operations. The batch process can be triggered by multiple concurrent requests which could lead to duplicate inserts.

Problem: When a duplicate entry ConstraintViolationException happens , how do I ignore the exception and continue,since session gets into an inconsistent state after the exception and needs to be rolledback completely. (This is based on my understanding that since Hibernate does not guarantee the time of execution of the sql operations, only the sequence,an exception needs to be rolled back)

Requirement:I want to use database constraint violation rather than application layer handling of duplicate entries.

Please let me know if you have ever faced this scenario before or if you have any suggestions.
Thanks,
Naveen.


Top
 Profile  
 
 Post subject: ideas
PostPosted: Thu Feb 16, 2006 7:18 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
1.Try to check if the object already exists, a named SQL query seems to be appropriate.
2.Have all the requests handled by the same session;
3.Try using session.merge()

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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