Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

java - JPA 2.0 : what is javax.validation.* package?

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;
    ...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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…


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...