I’m migrating a legacy application with spring-orm-6.x with Hibernate 6.1.6.Final version. While running the application, the at new HibernateTemplate(session), following error is being thrown: Caused by: java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) … 158 more
When tried to find this class, this looks to be removed from hibernate 6.x versions. As soon I downgrade to hibernate 5.x version this works fine and HibernateTemplate object gets created but I need to migrate to Hibernate 6.1.x version as this is the compatible version with spring framework 6.0. Please help on this asap.
I tried looking into build path related issues and removed all older versions but still issue persists.
Comment From: mdeinum
There is no Hibernate6 version of the HibernateTemplate
as it has been the recommendation for some time to use the plain Session
API (from Hibernate) in favor of the HibernateTemplate
. This is also mentioned in the javadoc of the HibernateTemplate
.
NOTE: Hibernate access code can also be coded against the native Hibernate
Session
. Hence, for newly started projects, consider adopting the standard Hibernate style of coding againstSessionFactory.getCurrentSession()
. Alternatively, useexecute(HibernateCallback)
with Java 8 lambda code blocks against the callback-provided Session which results in elegant code as well, decoupled from the Hibernate Session lifecycle. The remaining operations on this HibernateTemplate are deprecated in the meantime and primarily exist as a migration helper for older Hibernate 3.x/4.x data access code in existing applications.
With that said your best approach is to migrate to the use of the Session
API.
Comment From: bclozel
Indeed, the javadoc for HibernateTemplate
states the situation quite clearly, in addition to its method being @Deprecated
. I'm closing this issue as I don't think we can improve the documentation around it. This class will be removed when the hibernate5
support package is retired from Framework.