Make proxies truly Serializable
-------------------------------
Key: HHH-3463
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3463
Project: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6, database-independent
Reporter: Daniel Fernández
When I get a CGLIB entity proxy from hibernate, it is in an un-initialized state, but I
can serialize it anyway... if I do, and then de-serialize it, by the moment I call any of
its "getX()" methods, it tries to get initialized and... it fails with:
LazyInitializationException: could not initialize proxy - no Session
This is normal for me, but a little frustrating. Having a look at Hibernate's code, I
found that org.hibernate.proxy.pojo.cglib.SerializableProxy had the following
"readResolve" method:
private Object readResolve() {
try {
return CGLIBLazyInitializer.getProxy(
entityName,
persistentClass,
interfaces,
getIdentifierMethodName==null ?
null :
getIdentifierMethodClass.getDeclaredMethod(getIdentifierMethodName, null),
setIdentifierMethodName==null ?
null :
setIdentifierMethodClass.getDeclaredMethod(setIdentifierMethodName,
setIdentifierMethodParams),
componentIdType,
id,
null // <-- SESSION
);
}
catch (NoSuchMethodException nsme) {
throw new HibernateException("could not create proxy for entity: " +
entityName, nsme);
}
}
In which I can see that the last argument for that CGLIBLazyInitializer.getProxy call,
which is the session, is null. Of course, that is why it fails telling that there is no
Session from which to re-initialize the proxy... because the reconstructed proxy never
gets one.
So here my point is: could it be possible to make proxies truly serializable by making
them automatically retrieve a session when deserialized?
I understand that retrieving a session will first mean being able to know which session to
retrieve, but maybe something like SessionFactory.getCurrentSession() would do for all
people using some sort of "OpenSessionInView" pattern...
Thanks.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira