What is the javax.validation
package in Java EE? How to use this with JPA?
I want to validate my JPA Entity with the @NotNull
annotation. My JPA implementation is Hibernate.
Here's my Entity:
public class Employee implements Serializable , EmployeeDetail {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private int id;
private String name;
private long salary;
...
Using the Bean Validation Api you can quite easy ensure standard validation (not null, patterns, email) on your entities (or beans in common).
Check out Oracles tutorials for Bean Validation Api: http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html
Also Hibernate should be no problem with this, as it is the reference implementation: http://www.hibernate.org/subprojects/validator.html
For a good introduction check Hibernates tutorial on this topic: http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/
Some other tutorials (Google for JPA 2 + Bean Validation)
JSR specifications…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With