-->
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: How to use a ConstraintViolationException as information?
PostPosted: Tue Mar 20, 2007 2:39 pm 
Newbie

Joined: Tue Mar 20, 2007 2:03 pm
Posts: 1
Hibernate version:3.2
Name and version of the database you are using:Oracle 10g

Hi,

I have this simple question that seems to have no Hibernate solution since a ConstraintViolationException will force a rollback on a session.

The scenario:
Two separate processes A and B are processing messages from a same new user at the same time. Say process A will create the user record and it will need to know that it created user so it can go through initiation steps on the user. During the creation of the user, process B must wait until process A has completed. Once process A is completed, process B will just update the user.

Locking requirements: Pessimistic locking

Issue:
Using saveOrUpdate does not serve me because 1. the user id is taken from a sequence so it will always try to insert (there is a second key on the user combining service and address) and 2. saveOrUpdate does not tell us the record was created or updated.

Using save/persist will cause the process B to throw a ConstraintViolationException thus causing the Session to need a rollback. Since process B has pending commits on the session for other work it was doing I would rather just have a way to wait for the insert of process A to be committed instead of losing all the work done.

The question:
Is there any way via Hibernate to avoid the rollback when you have this situation? Post http://forum.hibernate.org/viewtopic.ph ... n&start=19 gives us a bypass Hibernate solution so I am guessing that I will not get the answer I want…

Ideally what I am asking for is for the “insert” to have the same waiting effect as a “select ... for update” on process B. Catching the ConstraintViolationException could be then treated with the concept of the Oracle “select ... for update nowait” in this case.


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.