gpt4 book ai didi

java - Hibernate 4 升级 (java.lang.NoSuchMethodError : javax. persistence.spi.PersistenceUnitInfo.getValidationMode())

转载 作者:行者123 更新时间:2023-11-30 08:28:00 24 4
gpt4 key购买 nike

我正在尝试将我的应用程序从 hibernate 3.4 升级到 4.1.0 FINAL 版本并出现下面提到的错误。

我现在正在使用 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>

下面是实体管理器和 session 工厂

    <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>

错误如下。

[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)

我点击以下链接升级应用程序。感谢帮助。

最佳答案

您的运行时是 Java EE 5(或更早版本),而代码需要 Java EE 6。查看 Java EE 5's PersistenceUnitInfo没有这样的方法 getValidationModel()。您可以通过将运行时升级到 Java EE 6 来简单地解决这个问题

关于java - Hibernate 4 升级 (java.lang.NoSuchMethodError : javax. persistence.spi.PersistenceUnitInfo.getValidationMode()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20482933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com