-->
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: many-to-one lazy initialisation
PostPosted: Wed Aug 25, 2004 12:06 pm 
Newbie

Joined: Wed Aug 25, 2004 11:47 am
Posts: 3
Why it's not possible to lazy initialize many-to-one mappings? Because now hibernate makes a lot sql queries, of whitch data is not used.
For example:
Item
{
Set subItems; // one-to-many
String name;
};
SubItem
{
SubItemType subItemType; //many-to-one
String name;
};
SubItemType
{
String name;
};

And now imagine Item has 100 subitems. I execute query "from Item it left outer join fetch item.subItems where it.name=:name";
And hibernates makes 1 + 100 queries for this select. If many-to-one mapping would be lazy, it'l make only 1 query and other querys only if I need subItemTypes. This is a big performance penalty I think.

And there are a lot of examples where lazy many-to-one is hitting on performance (object whith nested parents for example).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Why it's not possible to lazy initialize many-to-one mappings?


maybe because Hibernate can do lazy loading even for to-one assocations.

Just read the reference guide again

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 7:46 am 
Newbie

Joined: Wed Aug 25, 2004 11:47 am
Posts: 3
Reading reference once more, I found out, that to make many-to-one's lazy, you have to make a proxy for the class you are mapping (in my example to make proxy for SubItemType), because many-to-one doesn't have any property, whitch says about lazy loading. So in other words you have to make proxy for all your classes (in case you'll need lazy many-to-one in future). Is there any draw backs in such a move (exept those, that are written in manual - casting)? Is there any performance loss?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 8:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
the class can be it's own proxy by:
1- specifying lazy="true" in the class element
or- specifying proxy="theNameOfTheMappedClass"
2- coding a defaut constructor in your pojo

so there are no additionnal classes to write

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.