ken4ward
ken4ward

Reputation: 2296

Javassist ClassCastException in Hibernate and Netbeans

Could somebody help me look into this, what could have happened that is making this application generate this error. I am following this tutorial on using Hibernate in Netbeans. After getting to this line "from Film", that according to the tutorial it is to be executed to test to read the records of the Film table but the result is the error below. I googled to find what to do, all I have seen so far is that it's reported to be that the javassist jar file could be existing in different directories. One, in the Hibernate (Hibernate 4.x-javassist-3.15.0.GA) directory, which I found out to be true, and the other in the glassfish (Glassfish Server 4) directory. I tried searching for this in the glassfish lib directory, nothing like that seems to exist.

java.lang.ClassCastException: dvdstore.Language_$$_javassist_4 cannot be cast to javassist.util.proxy.ProxyObject
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:147)
    at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:71)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:631)
    at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3737)
    at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:360)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:281)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
    at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
    at org.hibernate.type.EntityType.resolve(EntityType.java:438)
    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
    at org.hibernate.loader.Loader.doQuery(Loader.java:857)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2542)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:940)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)

the list for jars for the project. The list of jar files for the project enter image description here

Upvotes: 2

Views: 3246

Answers (1)

Rafael Winterhalter
Rafael Winterhalter

Reputation: 43997

You are using a too old version of javassist. For Hibernate 4, you require a javassist version that is newer than 3.16. The same issue is discussed in this related question. Consider using a build tool like Maven or Gradle to build your project. These tools take care of resolving transitive dependencies for you such that you can avoid such version conflicts.

Upvotes: 3

Related Questions