Hi,
Thanks for all your suggestions...
But, remember I am in CMT, so all transaction demarcations are done declaratively. I don't get the exception until the container tries to commit, fails, and rollbacks the exception, in which case the client gets a RemoteException which wraps a JBossRollBackException which wraps the Hibernate StaleObjectStateException.
So, now you see, I have to do 2 things to handle this--not sure if this is the recommended way to do it:
1) Introduce another higher-level facade business layer, which calls the transactional layer that does Hibernate stuff, so that I catch this particular RemoteException and retry.
2) I need to specifically "peel" off the RemoteExeption 2 levels down and look for this particular StaleObjectStateException to detect an optimistic-lock failure. Other Hibernate failures are considered non-recoverable by us.
My point is, since the StaleObjectStateException is so "special", I think there is great value to have a notifier for it, so applications can choose to handle it or not.
Also, back to my original question...
Is it sufficient to "catch" optimistic-lock exception by extending off the DefaultFlushEventListener, intercepting the StaleStateException and throwing my own RuntimeException?
Is there any other listener I need to implement to catch optimistic-locking related exception?
Thanks,
Liem
|