Playframework:发生JPA错误(无法生成EntityManagerFactory)
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I started to contribute to one Play project in Java, downloaded code, created Play project, added libraries and set all I could and then created database. Finally everything seemed to be ok, but when i run localhost:9000 i get this error:

JPA error
@66kcmab39
Internal Server Error (500) for request GET /favicon.ico

JPA error
A JPA error occurred (Unable to build EntityManagerFactory): Unable to get the default  Bean Validation factory
play.exceptions.JPAException: Unable to build EntityManagerFactory
    at play.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:227)
    at play.Play.start(Play.java:427)
    at play.Play.detectChanges(Play.java:530)
    at play.Invoker$Invocation.init(Invoker.java:100)
    at Invocation.HTTP Request(Play!)
Caused by: org.hibernate.HibernateException: Unable to get the default Bean Validation factory
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:104)
at org.hibernate.cfg.AnnotationConfiguration.applyBeanValidationConstraintsOnDDL(AnnotationConfiguration.java:477)
at org.hibernate.cfg.AnnotationConfiguration.applyConstraintsToDDL(AnnotationConfiguration.java:429)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:403)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1459)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1086)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at play.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:225)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:95)
... 13 more
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:322)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:83)
... 14 more
Caused by: javax.validation.ValidationException: Unable to find a default provider
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:319)
... 15 more

Play version: 1.1.1
MySQL5
OS Ubuntu

Any idea what can be wrong?
Thanks
kvgr

#0

Good answer : you need to add the Hibernate Validator to your application.

#1

Make sure the JPA annotations (such as @Id and @OneToMany) are either:

(1) All immediately above the fields.

@Id
public Long id;

(2) Or, All immediately above the getter for the fields.

private Long id;

@Id
public Long getId(){
    return id;
}

Using a combination will lead to the error you are seeing.

// ERROR

@Id
private Long id;

private List<Child> children;


public Long getId(){
    return id;
}

@OneToMany
public List<Child> getChildren(){
    return id;
}

Note that some annotations such as:

@Constraints.Required

@Formats.DateTime(pattern="yyyy-MM-dd")

etc...

must be immediately above the field name. You cannot put these above the getters. But that's okay.

#2

As a complement, for adding the validator, add this to your dependencies.yml

Application dependencies

# Application dependencies

require:
    - play
    - org.hibernate -> hibernate-core 3.6.9.Final:
        force: true
    - org.hibernate -> hibernate-validator 4.2.0.Final   

推荐文章

呈现代码隐藏文件的内容而不是控件

呈现代码隐藏文件的内容而不是控件

推荐文章

选中列表框SetItemCheckState

选中列表框SetItemCheckState

推荐文章

无法让谷歌分析API在iPhone上注册页面视图

无法让谷歌分析API在iPhone上注册页面视图

推荐文章

只读计算属性,应该是方法吗?

只读计算属性,应该是方法吗?

推荐文章

为什么不“重写”工作?

为什么不“重写”工作?

推荐文章

WPF转换器转换导致Visual Studio设计器异常

WPF转换器转换导致Visual Studio设计器异常

推荐文章

用python登录facebook

用python登录facebook

推荐文章

如何使用NMS和C识别ActiveMQ断开连接#

如何使用NMS和C识别ActiveMQ断开连接#

推荐文章

ActiveRecord-自动将模型数据合并为聚合

ActiveRecord-自动将模型数据合并为聚合

推荐文章

是否可以不使用Windows身份验证w/a SQL Server文件流存储并对其中的文件使用流式访问?

是否可以不使用Windows身份验证w/a SQL Server文件流存储并对其中的文件使用流式访问?

推荐文章

使用@Resource加载环境条目

使用@Resource加载环境条目

推荐文章

使用LINQ2SQL在ASP.NET MVC中跨多个模型存储库共享数据上下文

使用LINQ2SQL在ASP.NET MVC中跨多个模型存储库共享数据上下文

推荐文章

谷歌关闭迷你在线?

谷歌关闭迷你在线?

推荐文章

我该如何使这些东西水平而不是垂直?

我该如何使这些东西水平而不是垂直?

推荐文章

WPF treeview itemselected删除项目时移动不正确

WPF treeview itemselected删除项目时移动不正确

推荐文章

在插入期间,哪些MySQL数据类型不应该被引用?

在插入期间,哪些MySQL数据类型不应该被引用?