-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Validator Constraint Violation
PostPosted: Tue May 19, 2009 2:09 am 
Newbie

Joined: Tue May 19, 2009 1:54 am
Posts: 4
Hi

I'm using Hibernate Validator (Version 3+), I was hoping to use an Annotation such as "Unique" on an Entity to signal to the Hibernate Validator that it should report an error if I have two beans with the exact same value in the "Unique" field. This doesn't seem to work. Another feature that I had hoped would be in Hibernate Validator is the ability to get error messages about ConstraintViolationException(s) from Hibernate. In other words - I still need to write code to check that the Entity that I am acting upon (either updating or deleting, etc) does not violate any constraints that I have set out using Hibernate Annotations. I then need to report these errors back to the UI. If I don't, then the user will get an ugly ConstraintViolationException. Is there any support for what I am looking for in Hibernate Validator? Or is the recommendation that we hand-code constraint checking?

Thanks for your input.

Martin


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Constraint Violation
PostPosted: Tue May 19, 2009 5:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
I'm using Hibernate Validator (Version 3+),

What exactly is 3+. Are you using 3.1.0 GA or a 4.0.0 Alpha/Beta version? There is a uge difference. Pre version 4.x Hibernate Validator was based on a different codebase. The 4.x version is now an implementation of the JSR 303 - Bean Validation.
Quote:
I was hoping to use an Annotation such as "Unique" on an Entity to signal to the Hibernate Validator that it should report an error if I have two beans with the exact same value in the "Unique" field.

Neither the the legacy (pre 4.x) nor the Bean Validation based Validator framework has a built-in annotation for that. However, either in both cases it would be quite easy to write a custom validator.
Quote:
This doesn't seem to work. Another feature that I had hoped would be in Hibernate Validator is the ability to get error messages about ConstraintViolationException(s) from Hibernate. In other words - I still need to write code to check that the Entity that I am acting upon (either updating or deleting, etc) does not violate any constraints that I have set out using Hibernate Annotations.

The next version of Hibernate (or better annotations) will automatically register the new Validator framework if it is on the classpath. For now you would have to write your own event listener. You can have a look at this code to see how it is done - http://fisheye.jboss.org/browse/Hiberna ... va?r=16516

Hope this helps.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Constraint Violation
PostPosted: Wed May 20, 2009 12:48 am 
Newbie

Joined: Tue May 19, 2009 1:54 am
Posts: 4
Hi Hardy

Thanks for the information. I'm using Hibernate Validator Version 3.1.0 GA, as I can't seem to find the equivalent documentation for version 4.x at https://www.hibernate.org/5.html#A17.
I'll investigate that code link that you supplied.
Has anyone else done something similar to validate Constraints?

Thanks,

Martin


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Constraint Violation
PostPosted: Wed May 20, 2009 2:31 am 
Hibernate Team
Hibernate Team

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

so far the documentation for Hibernate Validator 4.x is not deployed online. Instead it is shipped as part of the distribution package. The work on the documentation is still in progress, but there is a 'Getting Started' section and some basic examples. For more examples and a deeper understanding of the framework I recommend to look at the JSR 303 specification itself.

Also have a look at the Bean Validation Roadmap on the wiki - https://www.hibernate.org/459.html

Since you are using the 3.1.0 GA version it should automatically register itself when you are bootstrapping Hibernate, provided you are using the right version of Hibernate Annotations.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Constraint Violation
PostPosted: Wed May 20, 2009 2:43 am 
Newbie

Joined: Tue May 19, 2009 1:54 am
Posts: 4
Thank you very much, Hardy. I'll have a look at the documentation.

Kind regards

Martin


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Constraint Violation
PostPosted: Wed May 20, 2009 4:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
No worries.

You might also be interested in these set of blog posts from Gunnar who is a contributor to Hibernate Validator. Some of the entries are a little out of date since the specification was evolving, but it should give you a better idea on Bean Validation / Hibernate Validator 4.x

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Constraint Violation
PostPosted: Fri May 22, 2009 12:20 am 
Newbie

Joined: Tue May 19, 2009 1:54 am
Posts: 4
Thank you so much for being so helpful - that's great!


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