Playframework:发生 JPA 错误(无法构建 EntityManagerFactory)
我开始用 Java 为一个 Play 项目做贡献,下载代码,创建 Play 项目,添加库并设置所有我能做的,然后创建数据库。 最后一切似乎都正常,但是当我运行 localhost:9000 时,我收到此错误:
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
播放版本:1.1.1
MySQL5
操作系统 Ubuntu
知道可能出了什么问题吗?
谢谢
克瓦格
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的答案:您需要将 Hibernate Validator 添加到您的应用程序中。
Good answer : you need to add the Hibernate Validator to your application.
确保 JPA 注释(例如 @Id 和 @OneToMany)是:
(1) 全部紧邻字段上方。
(2) 或者,全部紧接在字段的 getter 上方。
使用组合将导致您看到的错误。
请注意,一些注释,例如:
@Constraints.Required
@Formats.DateTime(pattern="yyyy-MM-dd")
等...
必须紧接在字段名称上方。你不能把它们放在吸气剂之上。但没关系。
Make sure the JPA annotations (such as @Id and @OneToMany) are either:
(1) All immediately above the fields.
(2) Or, All immediately above the getter for the fields.
Using a combination will lead to the error you are seeing.
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.
作为补充,为了添加验证器,请将其添加到您的 dependency.yml
应用程序依赖项
As a complement, for adding the validator, add this to your dependencies.yml
Application dependencies