Hi,
I'm upset about the hibernate handling of ConstraintViolationException. It invalidates the session. I use TRANSACTION_READ_COMMITTED and want to avoid pessimistic locks as much as possible.
I have many cases of idempotent get/create for relationships, an example being a category path. For this example, the subpaths have parent/child relationships. I want to set a unique constraint on the db, such that only one parent/child relationship for those id pairs is allowed.
I have multiple threads that want to get/create the category path. It would seem logical that if a getter got null, then it could create the relationship it needed, catching ConstraintViolationException and getting again to get the same relationship that another thread committed. And continuing the session to get/create other parts of the subpath of the full category path.
However, Gavin King et alia didn't permit this design paradigm, and I am forced to use an optimistic get, and if I get null, then do a pessimistic lock.
When are the authors of Hibernate going to change this?
Andy
|