2

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

ken4ward
  • 2,246
  • 5
  • 49
  • 89
  • Are you building your project with Maven? Can you do a `dependency:tree` on your project and paste the output? You are most likely using a *too new* version of javassist that is not compatible to Hibernate. – Rafael Winterhalter Apr 24 '14 at 07:36
  • No, I am not using Maven, just a web project. I have edited the project to add the list of jar files I'm working with. Thanks.very grateful. – ken4ward Apr 24 '14 at 09:05

1 Answers1

3

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.

Community
  • 1
  • 1
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • 1
    Thanks very much. I think this should solve the riddle. Appreciate. I'll convert the project to Maven project and see if it offers a better performance. – ken4ward Apr 24 '14 at 10:32
  • Hey, Maven is complex to get started with but on the long run, it is worth the effort. Personally, I prefer Gradle. If your question is answered, consider marking this question as solved. Thanks! – Rafael Winterhalter Apr 24 '14 at 10:54
  • Ok. Does gradle achieve the same thing as Maven for dependency management? I'll give it a try. Thanks. – ken4ward Apr 24 '14 at 11:53
  • It does, look at the example here: http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html – Rafael Winterhalter Apr 24 '14 at 12:18