I keep gettting LazyInitializationExceptions although I use setFetchMode() to initialize fields.
Any idea what I'm doing wrong?
Extract of my code:
Code:
Criteria criteria = session.createCriteria(EntryLinkDelta.class)
.createCriteria("providerEntryLink", "pel")
.createCriteria("pel.entry")
.add(Restrictions.idEq(id));
String[] required = { "providerEntryLink.providerData.dataKey", "oldValue", "newValue"};
for (int i = 0; i < required.length; i++) {
criteria.setFetchMode(required[i], FetchMode.JOIN);
}
List list = criteria.list();
session.close();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
EntryLinkDelta eld = (EntryLinkDelta) iterator.next();
log.debug("\t" + eld.getOldValue());
log.debug("\t" + eld.getNewValue());
log.debug("\t" + eld.getProviderEntryLink().getProviderData().getDataKey()); // LazyInitializationException
}
Extract of my POJOs:
Code:
class EntryLinkDelta {
private String oldValue;
private String newValue;
private ProviderEntryLink providerEntryLink;
// other properties and getters & setters
}
class ProviderEntryLink {
private Entry entry;
private ProviderData providerData;
// other properties and getters & setters
}
class Entry {
private Long id;
// other properties and getters & setters
}
class ProviderData {
private String dataKey;
// other properties and getters & setters
}
Stacktrace:
Code:
ERROR hibernate.LazyInitializationException - could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.jnj.gtsc.agent.commons.bankdir.pl.ProviderData_$$_javassist_6.getDataKey(ProviderData_$$_javassist_6.java)
at com.jnj.gtsc.agent.business.bankdir.business.BankDirDAOBL.getDetails(BankDirDAOBL.java:39)
at com.jnj.gtsc.agent.business.bankdir.session.BankDirDAOBLMgrBean.getDetails(BankDirDAOBLMgrBean.java:54)
at com.jnj.gtsc.agent.business.bankdir.session.BankDirDAOBLMgrBean_7cajfk_EOImpl.getDetails(BankDirDAOBLMgrBean_7cajfk_EOImpl.java:46)
at com.jnj.gtsc.agent.business.bankdir.session.BankDirDAOBLMgrBean_7cajfk_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:491)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:120)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:434)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:429)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)