Hibernate Validator 4.1.0.Beta1

Posted by    |      

Time has not been standing still for Hibernate Validator and I am happy to announce the 4.1.0.Beta1 release of Hibernate Validator. The focus towards the final 4.1.0 release is to add new custom constraints, provide enhancement which go beyond the Bean Validation specification and give the developers an annotation processor to verify the correct placement of constraints. You can see what is already implemented in this beta release by referring to the Jira release notes. The roadmap towards 4.1.0 can be seen here. On the custom constraint side we added @CreditCardNumber, @NotBlank and @URL and are planning to add @ScriptAssert for the next release. We also introduced a new interface ResourceBundleLocator which allows users to make a better use of ResourceBundleMessageInterpolator. Instead of just loading resource bundles from the classpath using ResourceBundle.getBundle, you can now provide a custom implementation of ResourceBundleLocator providing the ResourceBundleMessageInterpolator with the message resource bundles to use:

HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
ResourceBundleLocator defaultResourceBundleLocator = configure.getDefaultResourceBundleLocator(); 
ResourceBundleLocator myResourceBundleLocator = new MyCustomResourceBundleLocator(defaultResourceBundleLocator);
configuration.messageInterpolator(new ResourceBundleMessageInterpolator(myResourceBundleLocator));

Thanks to the great work of Gunnar Morling developers can now also use the new Hibernate Validator Annotation Processor. By adding the jar file hibernate-validator-annotation-processor-4.1.0.Beta1.jar to the classpath of their IDE project, they can get feedback about invalid placements of constraints. For example @Valid on a primitive type or a @Pattern constraint on a non string attribute. Prerequisite for this to work is that you are using a JDK 6. The configuration of the annotation processor is the same as for the Hibernate Metamodel Generator and can be seen here. The fully qualified name of the processor is org.hibernate.validator.ap.ConstraintValidationProcessor.

It would be great to get some feedback on the usability of the annotation processor. Also let us know which other custom constraints you would like to see in Hibernate Validator. Use the forum to discuss your ideas or create a jira issue in HV.

Enjoy, Hardy

P.S. Download is of course as usual either from the JBoss Maven repo or from SourceForge.


Back to top