我有java專案(版本8)
我將休眠版本從 5.0.3.Final 升級到 5.6.9.Final
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.9.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.6.9.Final</version>
</dependency>
升級休眠版本后,我嘗試運行我的 tomcat(版本 10.0.20),但收到下一個錯誤:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring/db-config.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Entity (wrong name: jakarta/persistence/Entity)
sessionFactory bean 看起來像這樣:
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
depends-on="flyway">
<property name="dataSource" ref="itpDataSource"/>
<property name="packagesToScan" value="com.imperva.itp.domain,com.imperva.itp.commons.domain"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgresPlusDialect</prop>
<prop key="configurationClass">org.hibernate.cfg.Configuration</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.id.new_generator_mappings">true</prop>
<prop key="hibernate.default_schema">${itp.db.username}</prop>
</props>
</property>
</bean>
我不知道這是否相關,但我的 Spring 版本是 4.3.30.RELEASE
運行不同的組合后:
hibernate 5.0.3.Final with tomcat 8: works properly
hibernate 5.0.3.Final with tomcat 10: works properly
hibernate 5.6.9.Final with tomcat 8: works properly
hibernate 5.6.9.Final with tomcat 10: doesn't work and the exception is thrown
有任何想法嗎?
uj5u.com熱心網友回復:
Tomcat 10 將包名稱從 javax 更改為 jakarta,第一個為 jakarta 包提供支持的 Spring 將是未來的 Spring 6。
目前,除非另行通知,否則 Spring 5 或之前的任何版本都不會與 Tomcat 10 一起使用。因此,在 Spring 6 出來之前,您應該等待使用 Tomcat 10。
Tomcat 9 可以很好地滿足您的需求。
uj5u.com熱心網友回復:
最后,我將 spring 升級到 5.3.20 并將 spring web 升級到 5.7.1,并將 javax.persistence 的所有參考更改為 jakarta.persistence 并且它起作用了。我保留了休眠版本 5.6.9.Final 和 tomcat 10
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/490055.html
上一篇:org.springframework.orm.jpa.JpaSystemException:不要更改對啟用了delete-orphan的集合的參考
