Bean Validation

What is Bean Validation

Bean Validation is a Java specification which

  • lets you express constraints on object models via annotations
  • lets you write custom constraints in an extensible way
  • provides the APIs to validate objects and object graphs
  • provides the APIs to validate parameters and return values of methods and constructors
  • reports the set of violations (localized)
  • runs in Java SE but is integrated in Java EE (6 and 7)
public class User {
    @NotNull @Email 
    public String getEmail() { return email; }
    public void setEmail(String email) { = email; 
    private String email;

public class UserService {
  public void createUser(@Email email,
                         @NotNull String name) {

While you can run validation manually, it is more natural to let other specifications and framework validate data at the right time (user input in presentation frameworks, business service execution by CDI, entity insert or update by JPA).

In other words, run once, constrain anywhere.

Learn more and get the specification...

Feed Latest news

Stay up to date, subscribe to the news feed.

XML namespace and JCP

04 June 2013

Antonio Goncalves, fellow JCP member and friend has asked me why Bean Validation XML's namespace has not moved from its original location to the location like other Java EE 7 specifications. I don't remember being aware that such a move was orchestrated so there are two possible reasons: I was never been made aware of...

Bean Validation 1.1 is a spec

02 May 2013

It's now official, these couple of years of work have made it into an official JCP specification. Bean Validation is also part of Java EE 7 which has been approved too a few of days ago. We have already discussed the features at great length here but to do a short summary: support for method and constructor...

Bean Validation 1.1 CR3 - Final Approval Ballot

21 March 2013

Bean Validation, Hibernate Validator (its Reference Implementation) and the Test Compatibility Kit have been handed over to the JCP for what is called the Final Approval Ballot. That's when the expert committee votes for the go / no-go of the specification going final as it is. We have found a few glitches when working...