-->
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.  [ 6 posts ] 
Author Message
 Post subject: Conceptual questions Urgent!!
PostPosted: Mon Jun 21, 2004 12:09 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hibernate 2.1.4
database mysql latest version

Hi there,
I am currently using session ejb with struts, the session ejb is using hibernate to access the database and serializing the data objects to struts front end. because i faced issues when i used lazy initialization with some of my objects escpecially on the parent side of a one to many relationship, so i switch off lazy initialization.

below is an example of what i am doing

addressbook -----(1 to many)----contactgroups----(1 to many)---contacts


all relationhips above are bidirectional meaning addressbook.getContactGroups(), contactGroup.getAddressBook(), contactGroup.getContacts(), contact.getContactGroup()

now what i want to ask is that becos lazy initialization is off, and when i want to get contact, in the ejb and pass contact to struts, will hibernate also get for me the parent contactGroup and the addressbook as well? IF that is the case, is it fetching the OTHER contacts in the parent contactGroup as well? and so on so forth upwards to the address book when other contactGroups are also retrieved and the graph continues?

what i am concerned about is performance. cos i just want to get a contact which is the lowest of all children.

or does lazy initialization(when set to false) work downwards from parent to child only and not upwards? if it work downwards, how far downwards will hibernate go, cos if the tree hierachy is too long or too big, i am afraid it might degrade performance. or does it stop at contactGroups if the middle child (contactGroups) has a lazy init set to true and i call addressbook.getContactGroups() and hibernate does not initialize the contacts in the contactGroups?

another thing is if lazy init is set to true to contactGroup, which means that the child contacts will not be retrieved together with it. so when i pass the contactGroup over to struts, and in struts, i want to get the contacts in that contactGroup, do i have to pass the contactGroup back to the session ejb and call contactGroups.getContacts() and return just the contacts alone? if i return the contacts alone, and in struts, i call the same contactGroup.getContacts(), will i still get the same contacts or do i need to reattach the contacts to the contactGroup again? if so how?

basically these are fundamental questions that i need to get straight before i would can use hibernate correctly and effectively without pulling down performance

Please help!!! This is urgent!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 3:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you don't lazy at the collection and don't proxy the entities (lazy at the class level), the whole graph will be loaded.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 3:58 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
erm...could you elaborate a little further? please.....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 6:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you have a bidirectional relationship, then yes, the whole graph will be loaded (Child -> Parent -> ChildS)
You have to break your graph (ie setting lazy=true at the collection level, or lazy="true" et the class level). to avoid this problem.

To solve your problem, set
Code:
<class name="contactgroup" lazy="true">
, then the contact.getContactGroup() will return a proxy and the parent will not be loaded until it is really needed.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 7:30 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
If to break the graph, i set lazy="true" at the collection level/class level, then what if i call contact contact.getContactGroup() at the web tier, dont you think i would be getting an error because i am not using hibernate directly in my struts but getting the data objects as a return value from my session beans which are using hibernate. I would like to think that this is an advantage of using hibernate (ability to serialize data objects across instead of using value objects) but how then would I connect the contact with its contactgroup when i call contact.getContactGroup() cos only the sessionbean is using hibernate? would i need to send the contact back across to the session bean and "reattach" the contactgroup to the contact object? what are the alternatives?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 9:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use OpenSessionInView pattern if you need lazy initailisation in the view.


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