These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SaveOrUpdateEventListener custom validation
PostPosted: Fri Nov 12, 2010 8:16 pm 
Newbie

Joined: Fri Nov 12, 2010 7:57 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.