-->
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: Multiple SQL queries performed
PostPosted: Tue Aug 10, 2004 6:56 am 
Newbie

Joined: Tue Aug 10, 2004 6:34 am
Posts: 2
Hibernate2

I have only just started using hibernate and am experiencing very large number of hits on the database when I am trying to query just one table.

For each Service issue it finds within the query it runs two sub queries to get the region codes and the products which are both one to many.

I do not want to use these objects and do not want the overhead of an extra 2 queries for each record that my original query brings back. I have tried lazy loading as can be seen below but am not sure if I am applying it correctly or if it is the right thing to do.

Regards

Stephen

Mapping documents:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.company.servicestatus.bo.ServiceIssue"
table="service_issue"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="ticketNo"
column="se_ticket_no"
type="int"
>
<generator class="native">
</generator>
</id>

<set
name="regionCodes"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ticket_no"
/>

<one-to-many
class="com.company.servicestatus.bo.IssueRegionCode"
/>
</set>

<set
name="products"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ticket_no"
/>

<one-to-many
class="com.company.servicestatus.bo.IssueProduct"
/>
</set>

<property
name="timestamp"
type="timestamp"
update="true"
insert="true"
column="se_timestamp"
/>

<property
name="name"
type="string"
update="true"
insert="true"
column="se_name"
/>

<property
name="department"
type="string"
update="true"
insert="true"
column="se_department"
/>

<property
name="briefDescription"
type="string"
update="true"
insert="true"
column="se_brief_descr"
/>

<property
name="detailDescriptionCLOB"
type="clob"
update="true"
insert="true"
column="se_detail_descr"
/>

<property
name="customerAffected"
type="string"
update="true"
insert="true"
column="se_cust_affected"
/>

<property
name="estimatedTime"
type="string"
update="true"
insert="true"
column="se_est_time"
/>

<property
name="priority"
type="string"
update="true"
insert="true"
column="se_priority"
/>

<property
name="status"
type="string"
update="true"
insert="true"
column="se_status"
/>

<property
name="modifiedTimestamp"
type="timestamp"
update="true"
insert="true"
column="se_mod_timestamp"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ServiceIssue.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>



Database: Oracle 8i


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 6:47 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
map the following classes: com.company.servicestatus.bo.IssueRegionCode and com.company.servicestatus.bo.IssueProduct with lazy="true"
e.g:
Code:
<class name="com.company.servicestatus.bo.IssueProduct" table="..." lazy="true">...

_________________
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 7:01 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
map the following classes: com.company.servicestatus.bo.IssueRegionCode and com.company.servicestatus.bo.IssueProduct with lazy="true"

this is usefull for to-one relationship...

in this case twogun seems to have well written his mapping files.

show hql query and check if you have something on the setters. If something tries to hit the collections, then the other queries are executed.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 7:20 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
anthony wrote:
this is usefull for to-one relationship...

Yes, I am wrong... missed set with one-to-many. In that case set should be lazy-initialized.

_________________
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 9:34 am 
Newbie

Joined: Tue Aug 10, 2004 6:34 am
Posts: 2
Thanks Anthony and shl,

on looking at the setter methods in the DTO they were loading the two sets causing my problem.


Regards


Stephen


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

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
don't forget to test "fetch" keyword, you'll need it later

_________________
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.  [ 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.