Hi,
Why doesn't Hibernate automate proxy casting to avoid having to do this manually as described here?
http://www.hibernate.org/hib_docs/v3/re ... ng-proxies
You can quite easily scan the bytecode for a casting operation and replace it with a Hibernate-safe call. For example:
Given:
(TargetType) myObject
replace it with:
(TargetType) Hibernate.getProxiedObject(myObject)
then define Hibernate.getProxiedObject() as:
Code:
if (object instanceof HibernateProxy)
{
HibernateProxy proxy = (HibernateProxy) object;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
return initializer.getImplementation();
}
else
return object;
Is there any reason we aren't already doing this? The benefit would be that you wouldn't need to introduce any Hibernate-specific calls in the code.