我开始为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的
OS Ubuntu
知道什么是错的吗?
由于
kvgr
答案 0 :(得分:2)
答案很好:您需要将Hibernate Validator添加到您的应用程序中。
答案 1 :(得分:2)
确保JPA注释(例如@Id和@OneToMany)是:
(1)所有字段都位于字段上方。
@Id
public Long id;
(2)或者,紧接在字段的getter上方。
private Long id;
@Id
public Long getId(){
return id;
}
使用组合会导致您看到的错误。
// ERROR
@Id
private Long id;
private List<Child> children;
public Long getId(){
return id;
}
@OneToMany
public List<Child> getChildren(){
return id;
}
请注意一些注释,例如:
@ Constraints.Required
@ Formats.DateTime(图案=&#34; YYYY-MM-DD&#34)
等...
必须位于字段名称的正上方。你不能把这些放在吸气剂之上。但那没关系。
答案 2 :(得分:0)
作为补充,要添加验证器,请将其添加到dependencies.yml
# Application dependencies
require:
- play
- org.hibernate -> hibernate-core 3.6.9.Final:
force: true
- org.hibernate -> hibernate-validator 4.2.0.Final