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.