I tried adding the
cascade option. I tried giving different values each time and nothing worked, i gave
cascade="persist, delete" did not worked, so i tried
cascade="persist" did not worked, so i tried
cascade="save-update" and this one gave me an exception, if i give this option, hibernate is generating "
insert" sql for user object and an "
update" sql for UserAddress object, so it is giving an exception. I tried giving
cascade="all", this too giving exception.
Here is my mapping file,
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-lazy="false" default-cascade="persist" default-access="property">
<!-- User Table Mapping -->
<class name="userprofile.layer.domain.User" table="USER">
<id name="userID" column="USER_ID">
<generator class="assigned" />
</id>
<property name="title" column="TITLE"/>
<property name="firstName" column="FIRST_NAME"/>
<property name="middleInitial" column="MIDDLE_INITIAL"/>
<property name="lastName" column="LAST_NAME"/>
<property name="emailAddress" column="EMAIL_ADDRESS"/>
<property name="createDateTS" column="CREATE_DATE_TS"/>
<one-to-one name="userAddress" class="userprofile.layer.domain.UserAddress" cascade="persist"/>
</class>
<!-- User Address Table Mapping -->
<class name="userprofile.layer.domain.UserAddress" table="USER_ADDRESS">
<id name="userID" column="USER_ID">
<generator class="foreign">
<param name="property">userObj</param>
</generator>
</id>
<!-- <one-to-one name="userObj" class="userprofile.layer.domain.User" constrained="true"/> -->
<property name="addressLine1" column="ADDRESS_LINE_1"/>
<property name="addressLine2" column="ADDRESS_LINE_2"/>
<property name="cityName" column="CITY_NAME"/>
<property name="stateProvince" column="STATE_PROVINCE"/>
<property name="countryCode" column="COUNTRY_CODE"/>
<property name="zipCode" column="ZIP_CODE"/>
</class>
</hibernate-mapping>
I commented out
<one-to-one mapping for the class "UserAddress", even that too didn't worked...
Quote:
So my only option is to call "save()" twice for "User" and "UserAddress" separately?
Can somebody help me........what is wrong in my mapping file....