-->
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.  [ 3 posts ] 
Author Message
 Post subject: Efective loading of more one-to-many mapped properties
PostPosted: Thu Oct 21, 2004 10:36 am 
Newbie

Joined: Thu Oct 21, 2004 9:12 am
Posts: 1
Hibernate version: 2.1.5

I inherited one ugly project of my colegue and I found it is realy far from 'efective'. I have tried to read about Hibernate in manual and make it better, but still don't know if I have the best possible solution or not..

I have class X with more array/list properties a, b, c .. mapped as one-to-many. I need to load all (or some interval) of Xs from database. The question is, how many queries Hibernate needs to do?

With one property I can use join fetch, but on second, third ... it does not help.

Next thing I have tried was to set batch-size on properties, it helps but works just with lists and it leads to n/batchsize queries minimaly.

Is there another way to solve this problem? Loading of such objects should be optimizable to one query for instances of X and one query for each property. So I don't know if Hibernate doesn't support it or I just have a bad mapping or something else..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 11:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1- open session
2- select a from a left fetch join a.bs
3- select a from a left fetch join a.cs
4- select a from a left fetch join a.ds


you'll have 3 queries that is better than 3*n

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 6:21 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
i've just had to do the same thing but it appears anthony's answers is loading the main class A each time??

well, sorry if i got that wrong (totally possible), but I decided to load my main class with 1 fetch and then to load the other collection directly.

Code:
Query q = session.createQuery(
                "from X as x " +
                "   left outer join fetch x.coll1 " +
                "where x.id = :xId"
            );
            q.setParameter("xId", idParam);
           
            X x  = (X) q.list().get(0);
               
            q = session.createQuery(
                  "from CollType as c " +
                    "where c.x.id = :xId"
            );
           
            q.setParameter("xId", idParam);
           
            x.setCollType(q.list());


this works but i don't know if it's the best way. It just seemed to me that select from a with a fetch for B, C and D was heavy in comparison??


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