I face same issue in my spring-boot application and waste my so much time to solve it.
Issue is generate because of classloaders.
Classloaders of Model class and Session class both are different.
System.out.println("ClassLoader : " + Employee.class.getClassLoader());
System.out.println(session.getClass().getClassLoader()); //Hibernate Session object
ClassLoader : org.springframework.boot.devtools.restart.classloader.RestartClassLoader@a3af3c
sun.misc.Launcher$AppClassLoader@1d16e93
I face this issue because of this dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
When i comment this then my code working fine, so i suggest you to please check your jars.
System.out.println("ClassLoader : " + Employee.class.getClassLoader());
System.out.println(session.getClass().getClassLoader()); //Hibernate Session object
ClassLoader : sun.misc.Launcher$AppClassLoader@1d16e93
sun.misc.Launcher$AppClassLoader@1d16e93
Hope this answer help you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…