我今天决定尝试 Hibernate,它看起来很有希望,尽管设置可能更容易。在为前一百万个左右的配置错误找到解决方案后,我现在陷入了这个问题:
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: manager1] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
(...)
Caused by: org.hibernate.HibernateException: Bean Validation not available in the class path but required in javax.persistence.validation.mode
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyHibernateListeners(BeanValidationIntegrator.java:281)
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:134)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:303)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 5 more
持久性.xml:
<?xml version='1.0' encoding='utf-8' ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="manager1" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>net.zomis.hibernate.Game</class>
<class>net.zomis.hibernate.TestFields</class>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<validation-mode>CALLBACK</validation-mode>
<properties>
<property name="javax.persistence.validation.mode" value="NONE" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
</properties>
</persistence-unit>
</persistence>
(据我所知)的相关部分hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
(...)
<property name="hbm2ddl.auto" >validate</property>
<mapping class="net.zomis.hibernate.Game" />
<mapping class="net.zomis.hibernate.TestFields" />
</session-factory>
</hibernate-configuration>
我已尝试将其添加到构建路径中而没有任何更改。我已经用谷歌搜索了Bean Validation not available in the class path but required in javax.persistence.validation.mode
,也只是Bean Validation not available in the class path
. 我找到了源代码,但这对我没有多大帮助。
我还尝试从 xml 配置文件中删除属性,但没有任何运气。
我不使用 Maven。我只是使用 Eclipse 并直接从 Eclipse 构建和运行项目。
显而易见的问题是:我该如何解决这个问题?我是否需要在我错过的构建路径中添加一个 jar?(在那种情况下是哪一个?)还有:为什么需要它?我可以更改某些内容以使其不再需要吗?