Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

insert- update operation in hibernate  RSS feed

 
ved gunjan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I'm novice to the hibernate world...i've a simple application wherein i've <many-to-one relation between two valueobject.
Below is my .hbm.xml file.

<?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.manheim.cis.business.contact.beans.EntityAddressVO"
table="ENTADDR">
<composite-id >
<key-property name="entityId" column="ENT_ID" />
<key-property name="addrId" column="ADDR_ID" />
</composite-id>
<property name="addrType" column="ADDR_TYPE" />
<property name="effectiveDate" column="EFFECTIVE_DATE" />
<property name="businessUse" column="BUSINESS_USE" />
<property name="instruction" column="DELIVERY_INSTRUCTION" />
<property name="defaultAddr" column="DEFAULT_ADDR" />
<property name="optOutDate" column="OPT_OUT_DATE" />
<property name="optOutMethod" column="OPT_OUT_METHOD" />
<property name="optOutRequester" column="OPT_OUT_REQUESTER" />
<property name="expireDate" column="EXPIRE_DATE" />
<property name="createdDate" column="CREATE_DATE" />
<property name="createdBy" column="CREATE_BY" />
<property name="updatedTime" column="UPDATE_TIME" />
<property name="updatedBy" column="UPDATE_BY" />
<many-to-one name="addressVO" column="ADDR_ID"
class="com.manheim.cis.business.contact.beans.AddressVO"
insert="false" update="false" cascade="all">
</many-to-one>
</class>
<class name="com.manheim.cis.business.contact.beans.AddressVO"
table="ADDR">
<id name="addrId" column="ADDR_ID" unsaved-value="null" >
<generator class="increment"></generator>
</id>
<property name="addr1" column="ADDR1" />
<property name="addr2" column="ADDR2" />
<property name="city" column="CITY" />
<property name="county" column="COUNTY" />
<property name="state" column="STATE" />
<property name="zip" column="ZIP_CODE" />
<property name="countryName" column="COUNTRY_NAME" />
<property name="countryCode" column="COUNTRY_CODE" />
<property name="latitude" column="LATITUDE" />
<property name="longtitude" column="LONGITUDE" />
<property name="timeZone" column="TIMEZONE" />
<property name="createdDate" column="CREATE_DATE" />
<property name="createdBy" column="CREATE_BY" />
</class>
</hibernate-mapping>


This is the hibernate generated query:
insert into ADDR (ADDR1, ADDR2, CITY, COUNTY, STATE, ZIP_CODE, COUNTRY_NAME, COUNTRY_CODE, LATITUDE, LONGITUDE, TIMEZONE, CREATE_DATE, CREATE_BY, ADDR_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

insert into ENTADDR (ADDR_TYPE, EFFECTIVE_DATE, BUSINESS_USE, DELIVERY_INSTRUCTION, DEFAULT_ADDR, OPT_OUT_DATE, OPT_OUT_METHOD, OPT_OUT_REQUESTER, EXPIRE_DATE, CREATE_DATE, CREATE_BY, UPDATE_TIME,

UPDATE_BY, ENT_ID, ADDR_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
update ADDR set ADDR1=?, ADDR2=?, CITY=?, COUNTY=?, STATE=?, ZIP_CODE=?, COUNTRY_NAME=?, COUNTRY_CODE=?, LATITUDE=?, LONGITUDE=?, TIMEZONE=?, CREATE_DATE=?, CREATE_BY=? where ADDR_ID=?


My doubt is why hibernate is going for an update operation in to ADDR table after doing a insert in ADDR table and how to prevent it.
I've tried with all the possible combination of unsaved-value attributes in both the valueobjects/tables.

Also please can any one cleary explain the meaning of unsaved-value attributes and its possible values and how it is realted to the object beign persisted.

Thanx in advance for any kind of help!!!

Regards
Ved
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!