Hibernate 4 升级(java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode())
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20482933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate 4 upgrade (java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode())
提问by aanchal jain
I am trying to upgrade my application from hibernate 3.4 to 4.1.0 FINAL version and getting the below mentioned error.
我正在尝试将我的应用程序从 hibernate 3.4 升级到 4.1.0 FINAL 版本并收到以下提到的错误。
I am using spring 3.2 right now. and my pom file looks like the following.
我现在正在使用 spring 3.2。我的 pom 文件如下所示。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>com.springsource.org.hibernate</artifactId>
<version>4.1.0.Final</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Hibernate JPA Provider -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>com.springsource.org.hibernate.ejb</artifactId>
<version>4.1.0.Final</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Following is the entity manager and session factory
以下是实体管理器和会话工厂
<bean id="testSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
autowire="byName">
<property name="dataSource" ref="testDataSource" />
<property name="annotatedClasses">
<list>
<value>test</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="unit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="true" />
</bean>
</property>
<property name="dataSource">
<ref bean="datasource" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">"true"</prop>
</props>
</property>
</bean>
Following is the error.
以下是错误。
[ERROR] [main] 12-09 15:05:55,168 [ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [api-service.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:633)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at
[ERROR] [main] 12-09 15:05:55,169 [log] - Failed startup of context org.mortbay.jetty.webapp.WebAppContext@3a780024{/,file:/Users/Aanchal/avos/platform/src/avos-api/src/main/webapp/}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [api-service.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:633)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
I followed the following link to upgrade the application. Help is appreciated.
我按照以下链接升级应用程序。帮助表示赞赏。
回答by gerrytan
You're runtime is Java EE 5 (or older) while the code is expecteding Java EE 6. Looking at Java EE 5's PersistenceUnitInfothere's no such method getValidationModel()
. You might be able to fix this simply by upgrading runtime to Java EE 6
您的运行时是 Java EE 5(或更旧),而代码需要 Java EE 6。查看Java EE 5 的 PersistenceUnitInfo没有这样的方法getValidationModel()
。您可以通过将运行时升级到 Java EE 6 来解决此问题
回答by aanchal jain
I was using an 1.0.0 version of javax persistence lib
我使用的是 1.0.0 版本的 javax 持久性库
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>com.springsource.javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
Changing the version fixed it.,
更改版本修复它。,
回答by tyrantqiao
In my case, I use spring-boot-jpaand javax.persistence.jpawhich cause dependencies crashed. Delete javax.persistence.jpawill be helpful.
就我而言,我使用spring-boot-jpa和javax.persistence.jpa导致依赖关系崩溃。删除 javax.persistence.jpa会有所帮助。
Check your dependencies, check whether some dependencies are repetitive. (mvn dependency tree) (In Idea click maven tools and click SHOW DEPENDENCIES
检查您的依赖项,检查某些依赖项是否重复。(mvn 依赖树)(在 Idea 单击 maven tools 并单击SHOW DEPENDENCIES