-->
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: Excessive amount of SQL updates created by Hivernate?
PostPosted: Wed Apr 20, 2005 11:24 pm 
Newbie

Joined: Fri Jan 30, 2004 12:56 am
Posts: 5
Location: Salt Lake City
I have a ( what I consider normal ) biderctional one-to-many / many-to-one mapping between a Contact and Referral table (see below). The Contact has a Set of Referrals. The Contact is used in the UI of a web application. The Contact may be updated. In the service/dao layer a saveOrUpdate is performed on the Contact. The generated sql seem to indicate that a select statement is issued for *each* of the Referrals contained in the Contact. There is also a select issued for the Contact. So if I have 10 referrals, Hibernate issues 11 selects (before any updates are considered) even if no changes have taken place to the contained Referrals. Is this normal or am I doing something wrong?

Hibernate version: 2.1.x

Mapping documents:
<class name="Contact" table="tbl_contact">

<id name="id" column="id" type="int" unsaved-value="null">
<generator class="native"/>
</id>

<property name="callerFirstName" column="caller_first_name" type="string"/>
<property name="callerLastName" column="caller_last_name" type="string"/>
<property name="callerInitial" column="caller_initial" type="string"/>
<property name="callerNoNameGiven" column="caller_no_name_given" type="boolean" />
<property name="callerRelationToConsumer" column="relationship_id" type="integer"/>
<property name="consumerFirstName" column="consumer_first_name" type="string"/>
<property name="consumerLastName" column="consumer_last_name" type="string"/>
<property name="consumerInitial" column="consumer_initial" type="string"/>
<property name="consumerDOB" column="consumer_birth_date" type="date"/>
<property name="formID" column="form_id" type="string"/>
<property name="contactRequestType" column="contact_request_type_id" type="integer"/>
<property name="contactType" column="contact_type_id" type="integer"/>
<property name="systemUserID" column="system_user_id" type="integer"/>
<property name="SSN" column="consumer_ssn" type="string"/>
<property name="consumerAge" column="age" type="integer"/>
<property name="address1" column="address1" type="string"/>
<property name="address2" column="address2" type="string"/>
<property name="city" column="city" type="string"/>
<property name="state" column="state_id" type="integer"/>
<property name="zip" column="zip" type="string"/>
<property name="zipExtension" column="zip_extension" type="string"/>
<property name="telephone" column="telephone" type="string"/>
<property name="areaCode" column="area_code" type="string"/>
<property name="email" column="email" type="string"/>
<property name="addressee" column="addressee_id" type="integer"/>
<property name="addresseeOther" column="addressee_other" type="string"/>
<property name="disabilityType" column="disability_type_id" type="integer"/>
<property name="gender" column="gender_id" type="integer"/>
<property name="fundingRequestType" column="funding_request_type_id" type="integer"/>
<property name="formDate" column="form_date" type="date"/>
<property name="utahResident" column="utah_resident" type="string"/>
<property name="wantsToApply" column="wants_to_apply" type="string"/>
<property name="willing" column="willing" type="string"/>

<!-- Contact aggregates a Set of Referrals -->
<set name="referrals"
lazy="true"
inverse="true"
cascade="save-update">
<key column="contact_id"/>
<one-to-many class="gov.utah.dhs.dspd.aims.domain.ContactReferral"/>
</set>
</class>

---------

<class
name="gov.utah.dhs.dspd.aims.domain.Referral"
table="tbl_referral"
>

<id name="id" column="id" type="int" unsaved-value="null">
<generator class="native"/>
</id>

<property
name="systemUserId"
type="int"
column="system_user_id"
not-null="true"
length="10"
/>
<property
name="createDate"
type="java.sql.Timestamp"
column="create_date"
not-null="true"
length="23"
/>
<property
name="comments"
type="java.lang.String"
column="comments"
length="160"
/>
<property
name="agencyId"
type="int"
column="agency_id"
not-null="true"
length="10"
/>
<property
name="typeReferral"
type="java.lang.String"
column="type_referral"
not-null="true"
length="8"
/>



<!-- Associations -->
<many-to-one
name="contact"
not-null="true"
column="cid"
class="gov.utah.dhs.dspd.aims.domain.Contact"/>
</class>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: Sybase Adaptive Server Anywhere

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Issues Selects Before Updates
PostPosted: Thu Apr 21, 2005 4:54 am 
Beginner
Beginner

Joined: Wed Apr 21, 2004 8:33 am
Posts: 27
Hi
When hibernate tries to update , it does a select first on the table , only if something is changed the update will be issued otherwise the update wont be issued. also you can try in the many-to-one mapping put insert=false update=false and check

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 5:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is not correct.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 11:33 am 
Newbie

Joined: Fri Jan 30, 2004 12:56 am
Posts: 5
Location: Salt Lake City
Thanks for the replies. I'm not sure how to interpret the last message. Is it the mapping that is not correct? Or, is the last reply not correct?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 11:39 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Reply is not correct.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 12:21 pm 
Newbie

Joined: Fri Jan 30, 2004 12:56 am
Posts: 5
Location: Salt Lake City
Any thoughts on what is wrong?


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.