Thread:
 force initialization 
 jkookie   07 Jul 2006, 13:03 
 Re: force initialization 
 motravo   07 Aug 2006, 00:59 
 Re: force initialization 
 motravo   07 Aug 2006, 01:36 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: motravo (07 Aug 2006, 00:59) Replies: 1, Views: 24761
Subject: Re: force initialization
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.
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]