Hello everyone,
I'am using
Hibernate V2,
without Spring.
On my class SptUserImpl , I have
"lazy=true" on a collection.
Here is my mapping :
Code:
<hibernate-mapping>
<class
name="sg.sprint.core.logic.bean.common.user.SptUserImpl"
table="UserLogin">
<bag
name="clientLegalVisibilityCodes"
table="UserLegalEntity"
lazy="true"
cascade="none">
<key
column="UserId">
</key>
<element
column="LegalEntityCode"
type="string"
not-null="false"
unique="false"/>
</bag>
</class>
</hibernate-mapping>
When I load the user, I do :
Code:
public SptUser loadUserLegalEntity(SptUser user) throws DatabaseException {
SptUserImpl userImpl = (SptUserImpl) user;
Session s = null;
try {
s = openSession();
s.load(userImpl, userImpl.getId());
if (!Hibernate.isInitialized(userImpl.getClientLegalVisibilityCodes())) {
Hibernate.initialize(userImpl.getClientLegalVisibilityCodes());
}
} catch (HibernateException e) {
handleHibernateException(e, methodName);
} catch (Throwable t) {
handleUnexpectedException(t, methodName);
} finally {
closeSession(s, methodName);
}
return userImpl;
}
This method generate a LazyInitializationException :
Code:
Class :
class net.sf.hibernate.LazyInitializationException
Cause :
net.sf.hibernate.exception.JDBCConnectionException: could not initialize collection:
But not all the times ! Often enough to bother my users but not every time.
Can anyone explain to me where this JDBCConnectionException comes from ?
Thank you in advance