-->
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.  [ 2 posts ] 
Author Message
 Post subject: Handling of Errors thrown by BeanValidationEventListener
PostPosted: Tue Feb 05, 2013 6:01 am 
Newbie

Joined: Tue Feb 05, 2013 5:51 am
Posts: 1
Hi,

We have a web application where we are using Hibernate Persistence provider and Spring Transaction Manager. The Entities have validation annotated properties. The Hibernate Version is 4.1. By default the Validation in the persistence layer is activated in Hibernate 4.1 as the BeanValidationEventListener is registered using the service discovery in one of the jars.

Now when the validation kicks in during the commit phase. The BeanValidationEventListener throws a ConstraintViolationException if validation fails. This exception is wrapped under RollbackException by the Hibernate Session Manager and then again wrapped under Spring's TransactionSystemException by the spring transaction manager. It is very difficult for the caller service to know if the error is due to Constraint Violation as the caller has to get the lowest exception to find out the Constraints which caused the error.

Do we have any other mechanism to catch these exceptions.

Few thoughts:
I don't want to disable the BeanValidationEventListener and call the Hibernate Validate method and handle exceptions. Can we override the BeanValidationEventListener?


Top
 Profile  
 
 Post subject: Re: Handling of Errors thrown by BeanValidationEventListener
PostPosted: Wed Feb 06, 2013 2:24 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi you could try to implement an AOP advice, invocation handler or similar which catches all exceptions and does the unwrapping of the internal ConstraintViolationException, so this would be transparent for callers.

What do you exactly mean by "overriding the BeanValidationEventListener"?

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


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

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.