On 07 Jul 2006 13:03, jkookie wrote:
>Can't polymorphic classes and CGLIB be handled with the static
>initialize method e.g
>public void forceInitializeProxy(Object o) {
> if(!Hibernate.isInitialized(o)){
> Hibernate.initialize(o);
> }
> }
That wouldn't work. Say you have:
class Super {}
and
class Sub extends Super {}
and you call session.load(Super.class,4). (Some of the resulting objects
may be Subs.) Assuming Super is set up for lazy fetching, what you will
get are objects whose runtime type is something like:
class Super_HibernateProxy extends Super {}
So the objects you have are not Subs, and calling Hibernate.initialize()
is not going to change their class.
I wish Hibernate provided a way to load an object non-lazily for just a
single query. There are some cases (for instance, when displaying
properties of persistent subclass in your presentation layer) where
using a Visitor is not convenient.
I'd also settle for a static method in org.hibernate.Hibernate that
loaded the concrete subclass object given a proxy object. |