Hello all -
I'm trying to persist/update an object to the DB. This object has two collections in it (the array elements seen below in the mapping). When I
save() or
persist(), everything works fine. I get two beautiful INSERT statements:
Code:
Hibernate: insert into UPLOADED_ALLOCATIONS_OMS (<lots of columns...>) values (<lots of question marks...>)
Hibernate: insert into UA_OMS_BANKS (<lots of columns...>) values (?, ?, ?, ?)
However, whenever i make a change to the parent object and call update(), it seems that Hibernate insists on deleting the rows out of the array's table and reinserting them each time. Is there a way to prevent this sort of cascading? I've tried setting
cascade="none" on the array element but that didn't help. I also tried
cascade="persist," thinking that it would then only cascade down to the array in the event of a
persist() call but that didn't help either.
Something like
lazy="true" would be nice i guess but that isn't available for <array>. I know I should probably use a <bag> instead but i don't have control over this object (part of an API).
Any help would be appreciated. Please let me know if I need to provide more information.
Thanks.
-Marc
Hibernate version: 3.0.5
Mapping documents:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.foo.omsconnector.model.BlotterReqWrapperImpl"
table="UPLOADED_ALLOCATIONS_OMS"
>
<composite-id
name="blotterReqWrapperPK"
class="com.foo.abcconnector.model.BlotterReqWrapperPK"
>
<key-property
name="uploadDataId"
column="UPLOAD_DATA_ID"
/>
<key-property
name="recordId"
column="RECORD_ID"
/>
</composite-id>
<property
name="opType"
column="OP_TYPE"
/>
<property
name="status"
column="STATUS"
not-null="true"
/>
<property
name="message"
column="MESSAGE"
/>
<component
name="blotterReq"
class="com.foo.shared.quickabc.order.BlotterRequirementImpl"
insert="true"
update="true"
>
<property
name="parentIdKey"
column="OMS_ORDER_ID"
/>
<property
name="custOrderId"
column="CUST_ORDER_ID"
/>
<property
name="IdKey"
column="OMS_ALLOCATION_ID"
/>
<property
name="custRequirementId"
column="CUST_ALLOCATION_ID"
/>
<property
name="ccyPair"
column="CCY_PAIR"
not-null="true"
/>
<property
name="externalAccount"
column="ACCOUNT"
not-null="true"
/>
<property
name="dealtCcy"
column="DEALT_CCY"
not-null="true"
/>
<property
name="amount"
column="AMOUNT"
not-null="true"
/>
<array
name="banks"
table="UA_OMS_BANKS"
>
<key>
<column name="UPLOAD_DATA_ID"/>
<column name="RECORD_ID"/>
</key>
<list-index column="BANK_SEQID"/>
<element column="BANK_NAME" type="java.lang.String"/>
</array>
<property
name="mt304"
column="MT304_FLAG"
/>
<property
name="ssiFlag"
type="yes_no"
column="SSI_FLAG"
not-null="true"
/>
<property
name="remarks"
column="REMARKS"
/>
<property
name="sourceID"
column="SOURCE_ID"
/>
<property
name="sendDetailsSpotRate"
column="SEND_DETAILS_SPOT_RATE"
/>
<property
name="sendDetailsFwdPoints"
column="SEND_DETAILS_FORWARD_PTS"
/>
<property
name="sendDetailsAllInRate"
column="SEND_DETAILS_ALL_IN_RATE"
/>
<property
name="linkedDealRef"
column="LINKED_DEAL_REF"
/>
<array
name="udfs"
table="UA_OMS_UDFs"
>
<key>
<column name="UPLOAD_DATA_ID"/>
<column name="RECORD_ID"/>
</key>
<list-index column="UDF_SEQID"/>
<composite-element class="com.foo.shared.quickabc.order.BlotterUDFImpl">
<property
name="name"
column="UDF_NAME">
</property>
<property
name="value"
column="UDF_VALUE">
</property>
</composite-element>
</array>
</component>
<property
name="direction"
column="DIRECTION">
</property>
<property
name="allocationType"
column="ALLOCATION_TYPE"
/>
<property
name="valueDate"
column="VALUE_DATE"
not-null="true"
/>
<property
name="createdOn"
column="CREATED_ON"
not-null="true"
/>
<property
name="createdBy"
column="CREATED_BY"
not-null="true"
/>
<property
name="registeredOn"
column="REGISTERED_ON"
/>
<property
name="callbackReceivedOn"
column="CALLBACK_RECEIVED_ON"
/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Transaction tx = session.beginTransaction();
for (Iterator iter = blotterReqWrappers.iterator(); iter.hasNext();) {
BlotterReqWrapper blotterReqWrapper = (BlotterReqWrapper) iter.next();
getHibernateTemplate().update(blotterReqWrapper);
}
tx.commit();
Name and version of the database you are using: Oracle 9i
The generated SQL (show_sql=true): Code:
Hibernate: update <lots of columns...> where UPLOAD_DATA_ID=? and RECORD_ID=?
Hibernate: delete from UA_OMS_BANKS where UPLOAD_DATA_ID=? and RECORD_ID=?
Hibernate: delete from UA_OMS_UDFs where UPLOAD_DATA_ID=? and RECORD_ID=?
Hibernate: insert into UA_OMS_BANKS (<lots of columns...>) values (?, ?, ?, ?)