I have java project (version 8)
I upgraded my hibernate version from 5.0.3.Final to 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>
I tried to run my tomcat (version 10.0.20) after upgrading the hibernate version and I received the next error:
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)
The sessionFactory bean looks like that:
<bean id="sessionFactory"
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>
I don't know if it is relevant but my Spring version is 4.3.30.RELEASE
after running different combinations:
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
any ideas?
CodePudding user response:
Tomcat 10 changed package names from javax to jakarta, the first Spring that will provide support for jakarta packages will be future Spring 6.
At the moment, and until further notice, Spring 5, or any version before will not be working with Tomcat 10. So until Spring 6 is out, you should wait with the usage of Tomcat 10.
Tomcat 9 will work just fine for your needs.
CodePudding user response:
in the end I upgraded the spring to 5.3.20 and spring web to 5.7.1 and I changed all the references of javax.persistence to jakarta.persistence and it worked. I kept the hibernate version 5.6.9.Final and tomcat 10