Hibernate version: 3.3.2
Hello hibernate community,
I am facing a recursion problem due to a validation method called from within a SaveOrUpdateEventListener. Within the validation method a DAO call is executed which seems to trigger other SaveOrUpdate-events though it is a read only call. The concrete case is a User class that is checking from it's validation code whether a user with the assigned name already exists. The User itself does not cascade to any referenced object but an Employee object references the User entity with cascade all. If the User validation method is called and it executes the query by calling the corresponding DAO it seems as if the User object within the session being refreshed causes the Employee to be re-saved too, which causes an infinite recursion. Current ideas so far to prevent this are:
- Trigger validation within the service layer (I'd prefer not to since I would have to take all cascades into account for validation manually)
- Check whether the current entity is validated and do not delegate calls to the DefaultSaveOrUpdateEventListener (complex since I am using a chain, that contains many listeners and checks should be performed at the beginning of the chain execution, which would require another listener at the first index and an intermediate map that stores session and entities currently processed)
- Let the database handle the constraint (in this case possible but for more complex validation maybe not sufficient)
Any advice / hint for best practice would be greatly appreciated
Regards Jakob
Kind of an old related post:
https://forums.hibernate.org/viewtopic. ... 7#p2262707