JPA 2.0:什么是javax.validation *包? [英] JPA 2.0 : what is javax.validation.* package?

查看:332
本文介绍了JPA 2.0:什么是javax.validation *包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么 javax.validation。* 包在Java EE,如何使用JPA 2.0使用?我想验证我与 @NotNull 标注Enity。我的JPA实现休眠:

 公共类员工实现Serializable,EmployeeDetail {
    私有静态最后的serialVersionUID长1L =;    @ID
    @GeneratedValue
    私人诠释身份证;    私人字符串名称;    私人长期工资;
    ...


解决方案

(普通或豆类)在您的实体使用Bean验证API,您可以很容易保证标准的验证(不为空,图案,电子邮件)。

检查出的Bean验证API神谕教程:<一href=\"http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html\">http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html

Hibernate也应符合本没有问题,因为它是参考实现:<一href=\"http://www.hibernate.org/subprojects/validator.html\">http://www.hibernate.org/subprojects/validator.html

对于一个很好的介绍检查休眠有关此主题的教程:<一href=\"http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/\">http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/

其他的一些教程(谷歌的JPA 2 + Bean验证)

JSR规范...

what is javax.validation.* package in java ee , how to use this with JPA 2.0 ? i want to validate my Enity with @NotNull annotation . my JPA implementation is Hibernate :

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…

这篇关于JPA 2.0:什么是javax.validation *包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆