-->
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.  [ 3 posts ] 
Author Message
 Post subject: Validation: How to check if there are error messages
PostPosted: Sun Aug 14, 2011 4:11 pm 
Newbie

Joined: Sat Aug 13, 2011 10:54 am
Posts: 3
With hibernate validations I want to create error and warning messages. if there are only warning messages and the user checked a flag "Ignore warnings", I like to commit the transaction, even though there are messges.

Until now I get a ConstraintViolationException when I commit.

To make my app work I first have to check if there are any messages and if there are only warnings, I'd like to commit. To make commit possible I have to remove the messages before committing.

How do I make this work? How to check if there are messages and how to remove messages?

Regards Bertin


Top
 Profile  
 
 Post subject: Re: Validation: How to check if there are error messages
PostPosted: Mon Aug 15, 2011 4:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

first of, just working with the (ConstraintViolation) messages is not enough. You will have to do a little bit more. First of you will have to validate manually so that you can control the validation. Or even better write your own BeanValidationEventListener which listens to PreInsertEvent, PreUpdateEvent and PreDelete (have a look at https://github.com/hibernate/hibernate- ... tener.java). As you can see the default listener will always throw an exception on any validation error. There is no distinction between error or warning.

Once you have addressed the event listener issue you can look into distinguishing between error and warning messages. There are several ways to achieve this. You could for example place your constraints into different groups and first validate the 'error' group and then the 'warnings' group. If there are violations validating the warning groups you can react accordingly to your 'ignore warnings' flag.
Even better though would be to use the payload attribute for constraints. You can then specify the severity level of a constraint as a payload. The payload will be available as part of the constraint violation. In fact this is the example used in the online docs for Hibernate Validator. Have a look there for more information.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validation: How to check if there are error messages
PostPosted: Tue Aug 16, 2011 1:28 pm 
Newbie

Joined: Sat Aug 13, 2011 10:54 am
Posts: 3
this looks good, I will give it a try.

Thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.