-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Casting a CGLIB proxied class
PostPosted: Wed May 18, 2005 3:58 am 
Newbie

Joined: Wed May 18, 2005 3:32 am
Posts: 2
Location: Singapore
I recently went through a porting excercise where I was converting a huge domain mode (250+ classes) from using ObjectStore to Hibernate3. This presented some interesting challenges as this model had evolved over 5 years and was in its current state very object oriented. I probably touched most mapping aspect/challenges possible and learned alot about hibernate and ORM/caching/TX in general.

One issue that I found kind of hard to get around was the usage of Proxied classes (all classes by default in Hibernate3 - setting lazy="true") and type casting.

Looking aroung the net I found the recommendation.. specify lazy="false" for those classes where you need to type cast. In my case that meant making all baseclasses non-lazy. I tried that and can only say... bye bye to performance. It just doesnt work. The type of domain model I was working with (not an option to rewrite) I had to find another solution. We are talking a magnitude slower with lazy set to of.

Well I wrote my own narrower that I want to chare with you. Please have a go and see what you think. This utility class retreives that implementation of the proxy and works fine... I am using it at the moment. The performance is great.

Code:
public class ProxyConverter {

   public static Object convert(Object object)
   {
      if (object instanceof HibernateProxy) {
         HibernateProxy proxy = (HibernateProxy) object;
         LazyInitializer li = proxy.getHibernateLazyInitializer();
         return li.getImplementation();
      }
      else {
         return object;
      }      
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 7:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you dont have to have lazy="false" on your collections, keep those lazy.

btw. what you do below in your code is dangerous since you will be accessing the object directly and thus not guaranteed session scope identity.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 9:47 am 
Newbie

Joined: Wed May 18, 2005 3:32 am
Posts: 2
Location: Singapore
Hi Max, yes that is true, but I have to specify lazy=false on my baseclasses and that in itself caused the whole object graph to be loaded eagerly. It basically killed the app... The whole domain model was based around deeply nested hierachies.

Is there a way to specify laziness for a specifyc sublevel withouth having the whole graph loaded eagely?

Enabling the proxying feature really boosted the application.

The Session identity is important but isnt that associated with the Id property? Another thing to think about here it the dirty detection and updates.


/Mikael


Top
 Profile  
 
 Post subject: Loading entire object graph
PostPosted: Wed May 18, 2005 11:09 am 
Newbie

Joined: Fri Sep 26, 2003 11:44 am
Posts: 13
Hi,

Would the maximum fetch depth help? It controls how deep into the sub graph Hibernate will go while loading associated objects.

Regards,

Ali Ibrahim

_________________
Ali Ibrahim


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.