I'm using Hibernate 5.2.8-Final downloaded from Maven with all required dependencies and their required versions.
When I use session.load on any entity the following error occurs:
Code:
MyEntity e1 = session.load(MyEntity.class, "1");
ERROR - HHH000142: Bytecode enhancement failed: package.name.MyEntity
java.lang.ClassCastException: package.name.MyEntity_$$_javassist_110 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:123)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:761)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4587)
.
.
.
etc
Session.get works fine, but if the entity have any relationships mapped (eg. @ManyToOne) the same error occurs.
Digging into Hibernate code (more preciselly into the class
org.hibernate.proxy.pojo.javassist.JavassistProxyFactory) I found this:
Code:
final HibernateProxy proxy = (HibernateProxy) proxyClass.newInstance();
( (Proxy) proxy ).setHandler( initializer );
Also found that
org.hibernate.proxy.HibernateProxy and
javassist.util.proxy.Proxy doesn't extend or implement each other, so seems to me that type casting is problematic. Is this a bug?
If not I really don't understanding why is this hapening. Can someone help?
Thanks in advance.