I'm using hibernate 3.3 with session beans in a Jboss environment (JTA). I have an EJB that has two methods that can be called concurrently by two clients, and both methods can update different fields of a Person entity.
Because of concurrency I'm having same lost updates in the associate collections of my entity because of the commit order (that of course I don't manage cause is part of the JTA transactions). One example for ilustration.
1) Client A calls method 1. Method 1 update one object of 'addresses' collection in my Person object. 2) Client B calls method 2. Method 2 and add one object to the 'items' collection in my Person object. 3) Both methods exit almost concurrently, but method 2 commit first and updates of method 1 in the 'addresses' collection are lost and doesn't show any errors.
The person object is in memory and not retrieved in every method call, but is update with session.update(person) at first. Is there any thing I can do to manage this use case, and assure that commit of method 1 is call first? I suppose Lock.UPGRADE isn't a solution cause I'm having problems with the associations and not the object per se.
Thanks in advance and sorry for my english!
|