-->
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.  [ 8 posts ] 
Author Message
 Post subject: lazy class loading ignores subclass Lifecycle implementation
PostPosted: Thu Aug 11, 2005 6:43 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
Hi all,

Assume:
- SubClassA extends BaseClass.
- SubClassA implements Lifecycle but BaseClass does not.

If BaseClass is mapped as lazy=true (default) (and is not proxied, not final etc.) then you get back a CGLIB enhanced class, and the Lifecycle onLoad event is *not* called. If you set lazy=false then you get back the actual subclass and the events are called.

FYI.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 6:56 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
This is a problem of using proxy when you have inheritance.

In some situations, the cglib proxy, proxies the base class and then is not trully a subclass of your subclass.

This leads to problems with usage of 'instanceof'. So to avoid this problem you have to put lazy=false on your classes.

Also note that Lifecycle is deprecated in hibernate3. Prefer using interceptor in hibernate2 or events in hibernate3 to achieve what you want to do

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 7:40 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
Hi Seb.

Yeah, I ran into the "instanceof" problem when I realised the CGLIB class implements *all possible subclasses* :)

Problem with lazy=false is all single-point-associations are eagerly loaded :( In my domain that would be disastrous.

Haven't looked at interceptors.....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 8:20 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Are you sure this would be disastrous. Did you test it ? Single point associations are often fetch with join then you don't have more selects. Although, you just have to do that on classes that have inheritance. you can also use second level cache to improve performance on bottlenecks.
Check the difference and this if this is truly disastrous. (in my case, this is not)

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 8:25 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
It is in my case ;)

I have ObjectA one2one objectB one2one objectC.

I also have many (10s-100s) of instances of ObjectA that never need access to objectB.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 8:56 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
yatesco wrote:
It is in my case ;)

I have ObjectA one2one objectB one2one objectC.

I also have many (10s-100s) of instances of ObjectA that never need access to objectB.


Just curious, what version of Hibernate are you using ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 9:17 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
3.0.5


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 9:23 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
yatesco wrote:
3.0.5


If you use session.get() instead of session.load(), you don't get a proxy for your top-level object and your onLoad method will be called.

I'm not sure what all the differences are otherwise. I believe that load() will throw an Exception if the ID isn't found and get() will just return null, at least that was the behavior last time I looked into it.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.