I think I'd try pessimistic (db) locking. I'd suggest asking in the Hibernate forums to find out the best way to get the type of locking you want.
The problem is I don't use hibernate directly but through JPA, besides the hibernate's documentation says:
Hibernate will always use the locking mechanism of the database, never lock objects in memory!
But can't find description of behaviour when some thread tries to access an already locked row. It willl be blocked? an exception thrown?
Do you think is it possible to achieve this at the object level? by means of locking the entity bean itself?
It would be great to do this via some stablished and robust api, the previously cited documentation (Jboss 4.0 official guide) mentions something about it, but not in a useful hands-on way (at least to my taste).
Otherwise, is the only option left to implement this ?
Ok, perhaps the correct question is:
Does EJB3 persistence honors this aspects of Entity Bean Life Cycle (these behaviour is described in http://www.ubookcase.com/book/Sams/JBoss.4.0.The.Official.Guide/0672326485/ch05lev1sec4.html):
With the default configuration of JBoss there is only one active instance of a given entity bean in memory at one time
and the locking policy defined in each container configuration in standardjboss.xml:
I think if this two pieces are honored, then all I have to assure is the proper container-configuration (Standard CMP 2.x EntityBean) is in effect on my entity bean, what do you think??
please keep in mind by any means I'm not suggesting any disrespect via disinformation. I'm just kindly asking for some insight about this pessimistic locking issue, which at some point one self have to face.
PS: The reason I formulate the question as that is because the book Pro EJB3 JPA says the JPA doesn't support a portable way to do pessimistic locking.
Ask on EJB3 forum.