-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question about query performance.
PostPosted: Tue Sep 07, 2004 5:52 pm 
Beginner
Beginner

Joined: Fri Nov 28, 2003 11:21 am
Posts: 49
Location: Buenos Aires, Argentina
Hi, I have a class RM, with the following xml:

<class name="RM" table="T_RM" >
<id name="id" type="int" column="P_Id" unsaved-value="0">
<generator class="identity"/>
</id>
....
<property name="idSP" column="A_IdSP" type="int"/>
<many-to-one name="a" class="A" column="F_IdA" cascade="all"/>
<many-to-one name="b" class="B" column="F_IdB"/>
<one-to-one name="c" class="C"/>
<one-to-one name="d" class="D" />
</class>

the classes A, B, C and D don't have any association.

also I have the following query:
...
List rms = session.find("from Rm as rm where rm.idSP = " + 45);

this query is very slow, the total rows in the table T_RM is 130 and only 50 of them have A_idSP = 45. I set the property show_sql in true and saw that too much queries are made for each 'rm' to bring the objects A,B,C y D associated instead of making only one complex query for each 'rm'.
How can I improve this query? I have to use the property "outer-join"?
Thanks.
[b]Hibernate version:2.1.4[/b]

[b]Mapping documents:[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:MS SQL Server 7.0[/b]

[b]Debug level Hibernate log excerpt:[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 6:20 pm 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
When you access the relationships a,b,c or d then they are loaded when you access them (default is lazy=true). In this case you should use an outer join to fetch all associations with one query. Try something like this:
Code:
List result = session.createQuery("from Rm rm
left join fetch rm.a
left join fetch rm.b
left join fetch rm.c
left join fetch rm.d
where rm.idSP = :idsp")
.setInt("idsp",45)
.list();

Reto


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