Hi
I have a 'Work' Object that has many to one relation with 'User' object with the association name 'customer'. So 'Work' has getCustomer and setCustomer with return and input types as 'User'.
This problem has started appearing recently that when I load Work object, it either hangs or throws exception as below.
Quote:
Exception in thread "WorkReportCHUI" java.lang.NoClassDefFoundError: Could not initialize class econcinnity.usermanagement.User$$EnhancerByCGLIB$$b0a1e45b
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:616)
at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:609)
at net.sf.cglib.proxy.Enhancer.registerCallbacks(Enhancer.java:578)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyInstance(CGLIBLazyInitializer.java:110)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:93)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.getProxy(CGLIBProxyFactory.java:49)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:379)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3460)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:257)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:191)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:557)
at org.hibernate.type.EntityType.resolve(EntityType.java:379)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:120)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at econcinnity.util.persistence.HibernateUtil.getMatchingEntityWithPropertyExistingSession(HibernateUtil.java:200)
at econcinnity.work.reports.WorkReportCHUI.reportWork(WorkReportCHUI.java:57)
at econcinnity.work.reports.WorkReportCHUI.main(WorkReportCHUI.java:40)
This shows the User proxy object (CGLIB enhanced version) is tried to be loaded by the internal routines while suddenly it threw exception.
I can load the User object independently without any problem but when it is loaded as Proxy within Work object as part of association, it gives problem.
Code lines that are causing it
Code:
work = (Work) HibernateUtil.getMatchingEntityWithPropertyExistingSession(work, "workId");
Code:
public static Object getMatchingEntityWithPropertyExistingSession(Object o, String propertyName) throws Exception {
if (o != null && propertyName != null) {
Session session = getSession();
try {
String propertyValue = (String) GeneralUtils.getObjectProperty(o, propertyName);
Query query = session.createQuery("from " + o.getClass().getName() + " where " + propertyName + "='" + propertyValue + "'");
Log.debug("HibernateUtil.getMatchingEntityWithProperty HQL formed => " + query);
List results = query.list();
if (results == null) {
return null;
}
if (results.size() == 0) {
return null;
}
if (results.size() == 1) {
return results.get(0);
}
if (results.size() > 1) {
throw new Exception("More than one entities is matching");
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
return null;
}
Work.hbm.Xml
Code:
<hibernate-mapping>
<class dynamic-insert="false" dynamic-update="false" mutable="true" name="econcinnity.work.Work" optimistic-lock="version" polymorphism="implicit" select-before-update="false">
<id column="workId" name="workId">
<generator class="uuid"/>
</id>
<property name="offerTime"/>
<property name="acceptedTime"/>
<property name="completedTime"/>
<property name="rejectedTime"/>
<property name="serviceInstructions"/>
<many-to-one class="econcinnity.content.elements.Discussion" column="discussionID" name="workLog" unique="true"/>
<many-to-one class="econcinnity.work.WorkStatus" column="WORKSTATUSID" name="status" not-null="true"/>
<many-to-one class="econcinnity.usermanagement.User" column="CUSTOMERID" name="customer" not-null="true"/>
<many-to-one class="econcinnity.help.HelpSession" column="HELPSESSIONID" name="helpSession"/>
<many-to-one class="econcinnity.work.WorkTypeOfferStack" column="currentWorkTypeOfferStack" name="currentWorkTypeOfferStack" not-null="true" unique="true"/>
<set name="completedWorkTypeOffers" table="WORKCOMPLETEDOFFERS">
<key column="workId"/>
<many-to-many class="econcinnity.work.WorkTypeOffer" column="completedWorkTypeOfferId" unique="true"/>
</set>
<set name="workArtifacts" table="WORK_WORKARTIFACTS">
<key column="workId"/>
<many-to-many class="econcinnity.work.artifact.WorkArtifact" column="artifactId" unique="true"/>
</set>
</class>
</hibernate-mapping>
Please suggest why this could be appearing. Could it be that a required method is not found within User enhanced object but then I was able to load User object directly.
Thanks
Anusheel