JPA 2.0:什么是javax.validation.*包?

Har*_*ara 15 java annotations hibernate java-ee jpa-2.0

什么是javax.validationjava ee中的包,如何在JPA 2.0中使用它?我想通过@NotNull注释验证我的Enity .我的JPA实现是Hibernate:

public class Employee implements Serializable , EmployeeDetail {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private int id;

    private String name;

    private long salary;
    ...
Run Code Online (Sandbox Code Playgroud)

Adr*_*ian 14

使用Bean Validation Api,您可以非常轻松地确保实体(或共同的bean)的标准验证(非空,模式,电子邮件).

查看用于Bean Validation Api的Oracles教程:http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html

Hibernate也应该没问题,因为它是参考实现:http://www.hibernate.org/subprojects/validator.html

有关这个主题的Hibernates教程,请参阅http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/

其他一些教程(Google for JPA 2 + Bean Validation)

JSR规范......