-->
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: Inserting Collection with version tag
PostPosted: Wed Mar 17, 2004 3:55 pm 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
I have a cutomer object that contains a collection of phone objects. The mapping file looks like this ( Note both tables use the version tag).

customer.hbm.xml

<version name="updateCount" type="integer" column="UPDATE_CNT"/>

<bag name="phoneNumbers" inverse="true" cascade="all">
<key column="CUST_ID"/>
<one-to-many class="PhoneNumber">
</bag>

phonenumber.hbm.xml

<version name="updateCount" type="integer" column="UPDATE_CNT"/>

<many-to-one name="customer" column="CUST_ID" not-null="false"/>




Every time I try to insert a customer object with x phone numbers, in addtion to the inserts, I see 1 customer "update" and x phone number "update". This understandably sets the version to 1 in all the inserted rows.

My questions is, why does hibernate do an update after the insert. I want the version field to be 0 not 1.

These are the sql statements generated when i save a customer object with 2 phone number objects in the collection.

Hibernate: select CUST_SEQUENCE.nextval from dual
Hibernate: select PHONE_SEQUENCE.nextval from dual
Hibernate: select PHONE_SEQUENCE.nextval from dual

Hibernate: insert into SC01_CUST (CIF_ID, FRB_CD, NAICS_CD, SIC_CD, PREFERRED_NAME, BIRTH_DT, CITIZENSHIP_STAT, DRIVER_LIC_NBR, DRIVER_LIC_STATE, FIRST_NAME, LAST_NAME, MIDDLE_NAME, GENERATION, HONORIFIC, MARITAL_STAT, SALES_TAX_STAT, TIN, SS_COUNTRY_CD, UPDATE_CNT, CUST_NBR, PREFERRED_CONT, ORG_TYPE, PREFERRED_LANG, CLASS_TYPE, CUST_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'IND', ?)
Hibernate: insert into SE04_PHONE_NBR (UPDATE_CNT, CUST_ID, EFF_DT, EXP_DT, COUNTRY_CD, AREA_CD, PHONE_NBR, EXT, TYPE, SERVICE_IND, PHONE_NBR_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update SC01_CUST set CIF_ID=?, FRB_CD=?, NAICS_CD=?, SIC_CD=?, PREFERRED_NAME=?, BIRTH_DT=?, CITIZENSHIP_STAT=?, DRIVER_LIC_NBR=?, DRIVER_LIC_STATE=?, FIRST_NAME=?, LAST_NAME=?, MIDDLE_NAME=?, GENERATION=?, HONORIFIC=?, MARITAL_STAT=?, SALES_TAX_STAT=?, TIN=?, SS_COUNTRY_CD=?, UPDATE_CNT=?, CUST_NBR=?, PREFERRED_CONT=?, ORG_TYPE=?, PREFERRED_LANG=? where CUST_ID=? and UPDATE_CNT=?
Hibernate: update SE04_PHONE_NBR set UPDATE_CNT=?, CUST_ID=?, EFF_DT=?, EXP_DT=?, COUNTRY_CD=?, AREA_CD=?, PHONE_NBR=?, EXT=?, TYPE=?, SERVICE_IND=? where PHONE_NBR_ID=? and UPDATE_CNT=?
Hibernate: update SE04_PHONE_NBR set UPDATE_CNT=?, CUST_ID=?, EFF_DT=?, EXP_DT=?, COUNTRY_CD=?, AREA_CD=?, PHONE_NBR=?, EXT=?, TYPE=?, SERVICE_IND=? where PHONE_NBR_ID=? and UPDATE_CNT=?

Thanks in Advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 6:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Every update to the relation will update the parent version. The best advice is to let Hibernate do it's job on versioning

_________________
Emmanuel


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.