hibernatespring-ormhibernate-6.x

org.hibernate.criterion.Criterion ClassNotFoundException in migrating to Hibernate 6.1.6 with spring-orm 6.0.0


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.

I tried looking into build path related issues and removed all older versions but still issue persists.


Solution

  • Correct solution was to remove HibernateTemplate usage and use Session API instead in legacy code.