HibernateException: Javassist Enhancement failed

Home  >>  Java  >>  Hibernate  >>  HibernateException: Javassist Enhancement failed

HibernateException: Javassist Enhancement failed

13
Dec,2016

0

In one of my personal project, I struggled a lot for resolving this issue on JBOSS EAP-7. After so many trial and error, Though I am able to resolve this error but thought of blogging it so it may help others.

3
4
5
6
7
javax.persistence.PersistenceException: org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: com.anitech.xyz.entity.UserProfile
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) ~[hibernate-entitymanager-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) ~[hibernate-entitymanager-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492) ~[hibernate-entitymanager-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at com.anitech.xyz.dao.SessionManagerDAOImpl.findSessionByProfile(SessionManagerDAOImpl.java:53) [xyz.jar:?]

There are many reasons why you may get “Javassist Enhancement failed” exception. At the first glance it may look like a javassist jar conflict issue which is very common in JBOSS and you might find solutions like There might be multiple javassist jars available in your classpath on the internet. Unfortunately my scenario was different but somehow I got mislead by these solutions available on internet. For most of this kind of exceptions are mainly for 2 reasons:

PROBLEM – 1: There might be multiple javassist jars available in your classpath?
SOLUTION: Analyse and remove the duplicate javassist jar. If your project uses maven, you can verify the dependency tree using mvn dependency:tree command. Another alternative solution could be to exclude org.javassist module through jboss-deployment-structure.xml.

PROBLEM – 2: You may have @OneToMany(fetch=FetchType.LAZY) or @ManyToOne(fetch=FetchType.LAZY) in your entity class?
SOLUTION: Change FetchType.LAZY to FetchType.EAGER

Even though you get Javassist Enhancement failed exception on top of the error stack, The actual information you can found towards end of stack trace. My full exception stack trace was like below:

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Caused by: java.lang.ClassCastException: com.anitech.xyz.entity.UserProfile_$$_jvst84f_2b cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:123) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:666) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4462) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:359) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1129) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1022) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:632) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.type.EntityType.resolve(EntityType.java:424) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:154) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:128) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1133) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.processResultSet(Loader.java:992) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.doQuery(Loader.java:930) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.doList(Loader.java:2617) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.doList(Loader.java:2600) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.Loader.list(Loader.java:2424) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87) ~[hibernate-core-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) ~[hibernate-entitymanager-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483) ~[hibernate-entitymanager-5.0.9.Final-redhat-1.jar!/:5.0.9.Final-redhat-1]
... 68 more
Follow Me On:

Leave a Reply

Your email address will not be published.