Help

I am happy to announce the first beta release of Hibernate Validator 4.2. You can download this release as usual from the JBoss Maven Repository or from SourceForge.

As announced earlier, the highlight of the 4.2 release is the implementation of method level constraints (HV-347) as described in Appendix C of the Bean Validation specification. Many thanks to Gunnar for implementing this new feature. Method level validation allows to apply constraints to method parameters or return values like this:

public @NotNull String saveItem(@Valid @NotNull Item item, @Max(23) BigDecimal price)
To validate these constraints you would get hold of a MethodValidator via the Validator.unwrap() method:
MethodValidator validator = Validation.byProvider( HibernateValidator.class )
    .configure()
    .buildValidatorFactory()
    .getValidator()
    .unwrap( MethodValidator.class );
and use one of the following methods of this new interface:
public interface MethodValidator {
    public <T> Set<MethodConstraintViolation<T>> validateParameter(T object, Method method, Object parameterValue, int parameterIndex, Class<?>... groups);
    public <T> Set<MethodConstraintViolation<T>> validateParameters(T object, Method method, Object[] parameterValues, Class<?>... groups);
    public <T> Set<MethodConstraintViolation<T>> validateReturnValue(T object, Method method, Object returnValue, Class<?>... groups);
}
The returned MethodConstraintViolation is derived from ConstraintViolation and provides additional method level validation specific information. For example it can contain the method name and index of the parameter which caused the constraint violation. The documentation for this feature is still work in progress and will be completed in the following releases.

We except that the new MethodValidator API is in particular interesting when used in conjunction with APIs or frameworks like Contexts and Dependency Injection (JSR-299) or aspect oriented frameworks. With the help of these frameworks it is very simple to create an interceptor/aspect which automatically triggers validation of all method invocations and throws a MethodConstraintViolationExcepion in case of any validation errors. Let us know how you are going to use this new API.

Next to method level validation we also introduced boolean composition for composed constraints (HV-390). So far composing constraints were always a conjunction of all specified constraints. With this release Hibernate Validator introduces the @ConstraintComposition annotation together with the CompositionType enum. This allows you to define composing constraints like this:

@ConstraintComposition(OR)
@Pattern(regexp = "K")
@Size(min = 2, max = 10)
@ReportAsSingleViolation
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
@Constraint(validatedBy = { })
public @interface PatternOrSize {
	public abstract String message() default "OR";
	public abstract Class<?>[] groups() default { };
	public abstract Class<? extends Payload>[] payload() default { };
}
This is yet another contribution from the community. Thanks a lot for your support :)

Another new feature worth mentioning is the new ValueFormatterMessageInterpolator which allows you to interpolate the validated value in the message templates. To enable this new interpolator use the configuration API:

Validation.byProvider( HibernateValidator.class ).configure().messageInterpolator( new ValueFormatterMessageInterpolator() ).buildValidatorFactory();
Using the message parameter validatedValue and an optional format string you can interpolate the validated value. As example take a custom @Future constraint message - "${validatedValue:%1$td.%1$tm.%1$ty} is not in the future", which would interpolate into something like "13.01.11 is not in the future".

One note regarding backwards compatibility. Due to BVTCK-12 resp. HV-395 the javax.validation.Path implementation of Hibernate Validator needed some changes. The good news is, however, that unless you iterate over the Path instance returned by Constraint.getPropertyPath() you are not affected by this change.

Also the programmatic configuration of generic constraints has changes and looks like this now:

ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Foo.class )
    .property( "bar", FIELD )
    .genericConstraint( MyConstraint.class ).param( "value", 1 );
We also added a new type parameter to ConstraintDef which simplifies the creation of definition types for custom constraints. It is now not longer necessary to provide methods for standard constraint attributes such as message(). If you are using a custom ConstraintDef you will have to retrofit your implementation.

Of course this release contains also a whole range of other bug fixes and improvements. You can view the full changelog here. Thanks to Kevin who helped to fix many of these issues. To point out one of his contributions have a look at HV-307 which adds support for Joda Time types such as DateTime. These types can be annotated with @Past and @Future just as the standard JDK date types.

We are looking forward to your feedback on the Validator Forum. For bug reports please use the issue tracker.

31 comments:
 
13. Jan 2011, 15:30 CET | Link

Very nice! Thanks Serli via Kevin for their contribution. Actually it looks like Hardy did nothing but integrate contributions ;)

ReplyQuote
 
13. Jan 2011, 21:41 CET | Link
Federico Mancini

Nice to see that the boolean composition made it in the new release :) Thanks again for the support!

 
13. Jan 2011, 21:46 CET | Link

Congratulations on the release. Is it just a drop-in-jar-replacement on AS 6 Final?

 
14. Jan 2011, 09:45 CET | Link
Nicklas Karlsson wrote on Jan 13, 2011 15:46:
Congratulations on the release. Is it just a drop-in-jar-replacement on AS 6 Final?

Yes, Only if you make extensive use of the Path API or if use the programmatic constraints configuration you might have to make some adjustments.

 
14. Jan 2011, 11:30 CET | Link
Hardy Ferentschik wrote on Jan 14, 2011 03:45:
Nicklas Karlsson wrote on Jan 13, 2011 15:46:
Congratulations on the release. Is it just a drop-in-jar-replacement on AS 6 Final?
Yes, Only if you make extensive use of the Path API or if use the programmatic constraints configuration you might have to make some adjustments.

And you don't drop in this baby, you gently put it in place. Be human!

 
14. Jan 2011, 13:00 CET | Link
Federico Mancini wrote on Jan 13, 2011 15:41:
Nice to see that the boolean composition made it in the new release :) Thanks again for the support!

We have to thank you guys for your contribution :)

 
16. Jan 2011, 22:48 CET | Link

Those interested in the method validation feature can find some more detail information in my blog post Method Validation with Hibernate Validator 4.2.

If you want to try method validation out yourself you might be interested in the methodvalidation-integration project I started on GitHub which provides validation interceptors for CDI and Google Guice.

As Hardy wrote we are happy about any feedback on the Beta, so just give it a try.

 
18. Jan 2011, 11:05 CET | Link
Gunnar wrote on Jan 16, 2011 16:48:
Those interested in the method validation feature can find some more detail information in my blog post Method Validation with Hibernate Validator 4.2.

Nice blog. I added the link as well to the wiki page Hibernate Validator on the Web. It already contains several links to articles and blogs about Validator.

 
21. Jan 2011, 14:05 CET | Link

BTW, has there been any discussion regarding hooks for client-side validation integration with JSR-303 in some MR?

10. Jun 2014, 12:58 CET | Link

Actual product packaging and materials may contain more and different information than what is shown on our website. We recommend that you do not rely solely on the information presented and that you always read labels, warnings, and directions before using or consuming a product. Please see our full disclaimer below. check out here

13. Jun 2014, 08:43 CET | Link

We also offer an in-house licensed esthetician services. We offer plastic surgery in Medford Oregon and it's surrounding areas.website link

03. Jul 2014, 18:53 CET | Link

This site is a leading resource for information about the James Bauer What Men Secretly Want PDF book that teaches you how to keep a guy interested and exactly what he needs in your relationship if he's going to stick around.what do all men secretly want

 
30. Jul 2014, 09:05 CET | Link

La moda e la magnificenza delle donne orologi è comunque una seconda richiesta pensato di prendere in considerazione in precedenza che l'acquisizione. Allora, siete attualmente attualmente alla ricerca di donne replica orologio con quadranti quadrati o sferiche, affare gigante con, retro, fondamentale, alla moda, comune, metallico, convenzionale, nero o bianco? Opzioni top-of-the-line per risolvere sul leader osservare ordinamento per lei personalmente personalmente può essere quello di considerare solo una avere una sembrare a totalmente diversa sembrare in genere, valutare e optare per la adattandosi favoloso ordinamento per delineare il vostro personaggio.

30. Jul 2014, 11:09 CET | Link

There isn't any more grueling form of fast or perhaps cleansing diet when compared to a pure h2o fast. With this fast, it is possible to only have got water. In accordance with many choice health professionals, the health improvements can become extraordinary.information

31. Jul 2014, 08:40 CET | Link

This course came from the fact that Bobby and Rob continually got questions from guys that started with “So, there is this girl…” Most guys completely blow it with the girls they really like.theofficialwebsite.co/bobby-rio-and-rob-judge-unlock-her-legs-review/

31. Jul 2014, 11:16 CET | Link

Costa Rican real estate has been, and continues to be, a good investment because the country has a very stable political system and a growing economy.Of course, Costa Rica has felt the impact of the severe economic downturn in the States and Europe.jaco homes for sale

 
31. Jul 2014, 14:38 CET | Link
Sonsa

I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it. the venus factor

01. Aug 2014, 14:40 CET | Link

The Doggy Dan Online Dog Trainer has the unique distinction of being the world's only video based dog training website endorsed by the Society for the Prevention of Cruelty to Animals (SPCA) and many dog owners are having great results using Doggy Dan's training methods.online dog trainer program reviews

02. Aug 2014, 12:53 CET | Link

Many experts including buyers of Lake Life EC note that the site is a premium site for sale as it is very near to many schools available in the Jurong Lake District. Also, many amenities are also near Lake Life EC such as the Japanese Garden, Chinese Garden as well as Jurong Lake Part. Residents of Lake Life EC will get to enjoy the facilities and amenities right in the heart of Jurong.jurong lakelife ec

 
09. Sep 2014, 09:17 CET | Link
asadalikhatri

3 PXL Photography - Las Vegas, Nevada. USA. Wedding photography company.Las Vegas Wedding Photographers

 
09. Sep 2014, 09:32 CET | Link
asadalikhatri

Modern signage depends on words which are used with images. At times modern signage designed for international audience omits text. You can promote your business with the help of custom made signage.Web Design

11. Sep 2014, 14:23 CET | Link
asadalikhatri

Thanks for sharing this interesting blog with us.My pleasure to being here on your blog..I wanna come beck here for new post from your site. serangoon condo

12. Sep 2014, 06:30 CET | Link

The Oxygen Miracle Cure book is only available online through author Kevin Richardson's website and is NOT sold through Amazon, Barnes and Noble, or other traditional book sellers.https://rebelmouse.com/oxygenmiraclecurereviews/

12. Sep 2014, 12:05 CET | Link

Manifestation Miracle by Heather Mathews is a digital product and can be downloaded instantly after purchase in PDF (ebook) format or viewed directly online using your favorite web browser.https://rebelmouse.com/manifestationmiraclereviews/

12. Sep 2014, 12:41 CET | Link

Thanks for sharing this interesting blog with us.My pleasure to being here on your blog..I wanna come beck here for new post from your site. elektronik sigara

13. Sep 2014, 12:30 CET | Link

At the end of the day, I believe it's the consumer's responsibility to do their own due diligence before investing in any program, but I definitely want to share with you what I've discovered during my own research in case it helps.capture his heart and make him love you forever ebook reviews

14. Sep 2014, 08:24 CET | Link

Includes a collection of Michael Fiore Text The Romance Back reviews, PDF download information, and romantic texting tips from around the web.text the romance back michael fiore book review

16. Sep 2014, 10:28 CET | Link

Gain instant access to the natural and weird anti-inflammatory system for safely and permanently shrinking and eliminating nasal polyps with the help of world-renowned bio-medical researcher, health consultant, nutritionist, and author, Manuel Richards.how to destroy nasal polyps without surgery

17. Sep 2014, 11:04 CET | Link

The Customized Fat Loss For Men program is compatible with desktop and laptop computers, iPhones, iPads, and virtually any tablet, smart phone, or other device that has PDF viewing capabilities.specificazioni

17. Sep 2014, 21:13 CET | Link

The 101 Superfoods That Stop Your Joint Pain book is only available online through author Mike Westerdal's website and is NOT sold through Amazon, Barnes and Noble, or other traditional book sellers.https://www.rebelmouse.com/101superfoodsthatstopjointpain/

20. Sep 2014, 10:57 CET | Link

The first is the program you see here on this site, Restore My Vision Today (sometimes also called Perfect Vision Today) by Dr. Sen and Samantha Pearson which was just recently released in April 2014. The second is called Vision Without Glasses by Duke Peterson which has been around for years, is extremely popular, and is currently ranked as the 1 natural vision improvement guide in the Clickbank Marketplace.can you correct your vision without glasses

Post Comment