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.  [ 1 post ] 
Author Message
 Post subject: Hibernate3 Association JOINS
PostPosted: Sun Sep 30, 2007 7:37 pm 
Newbie

Joined: Sun Sep 30, 2007 6:50 pm
Posts: 8
I have some problem with retrieving graph of objects with Fetch_Mode=JOIN.

My code looks like:
************************************************
Criteria hCriteriaUser = hbmSession.createCriteria(User.class);
//add Restrictions on User.name like "John"
Criteria hCriteriaHistory = hCriteriaUser.createCriteria("histories".LEFT_JOIN).setFetchMode("histories", FetchMode.JOIN);
//add Restrictions on History, status="active"
List userList = hCriteriaUser.list();
*************************************************

User mapping file looks like:
************************************************
<class name="User" table="users" lazy="false">
.............................................
<set name="histories" lazy="true" cascade="save-update,lock" inverse="true">
<key column="USERID" not-null="true"/>
<one-to-many class="History"/>
</set>
.......................................
****************************************************

Issues:
1) By default it's also executing SELECT SQLs on all "one-one" and "many-one" the History association.
For example, if there is one matching User with 4 histories, it's basically creating 4 additional SQLs unnecessarily for all the {many} one-one History associations.
This is a performance hit; I just want only JOIN to be executed. How can we prevent unnecessary SQLs

2) As we are using LEFT_JOIN in the above scenario, it's not retrieving all matching Users if there is no corresponding matching History.
For example, if there 5 users with name "John" and for 3 users with matching History,
I'm expecting userList to have all 5 users with HISTORY as NULL for the remaining 2 users.
If I use INNER_JOIN it's throwing LAZY Initialization Exception on User.getHistory() in client side code.

Our application is performance sensitive. I would appreciate any inputs on resolving this problem.

Thanks,R.


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

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.