I accidentally posted this in NHibernate Users group. reposting ...
I have a class called Request that has an idbag of Comments. I am using the saveOrUpdate() method to save the request object. Based on the documentation, I should be updating the createTs column and better still, one would expect only new rows to be inserted. In fact, none of the existing rows should be updated. Currently, the way this works is, it re-creates all the records and uses the default value "sysdate" for the createTs column. Besides, it also uses new sequence numbers for re-inserting all the rows. Is there a way to ignore updates of rows and only do inserts within the collection? I tried various things and I just could not make it behave the way I wanted to.
Help!!!
Thanks!
Atul
Hibernate version: 3.1.3
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 package="com.dummyCompany.ittoolkit.ws.ccf">
<class name="Request" table="CR_REQUEST">
<id name="reqId" column="REQ_ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">CR_REQUEST_ID</param>
</generator>
</id>
<version name="version" column="VERSION"
type="long" access="field"
insert="false" />
<property name="altId" column="ALT_ID" />
<many-to-one name="reqState" column="REQ_STATE_ID" not-null="true" fetch="join"
class="com.dummyCompany.ittoolkit.ws.code.ReqState" />
<property name="breakFix" column="BREAK_FIX" />
<property name="title" column="TITLE" />
<property name="description" column="DESCRIPTION" />
<property name="urgency" column="URGENCY" />
<many-to-one name="reqTeam" column="REQ_TEAM_ID" fetch="join" class="ReqTeam" />
<property name="reqUserId" column="REQ_USER_ID" />
<property name="testUserId" column="TEST_USER_ID" />
<property name="projectName" column="PROJECT_NAME" />
<property name="startDate" column="START_DATE" type="calendar_date" />
<property name="schedDate" column="SCHED_DATE" type="calendar_date" />
<property name="migPathFrom" column="MIG_PATH_FROM" />
<property name="migPathTo" column="MIG_PATH_TO" />
<property name="onComplNotify" column="ON_COMPL_NOTIFY" />
<property name="changeDoc" column="CHANGE_DOC" />
<property name="testDoc" column="TEST_DOC" />
<property name="backoutDoc" column="BACKOUT_DOC" />
<property name="createTs" column="CREATE_TS" type="calendar" access="field" update="false" insert="false" generated="always" />
<property name="changeTs" column="CHANGE_TS" type="calendar" access="field" update="false" insert="false" generated="always" />
<property name="changeUserId" column="CHANGE_USER_ID" />
<property name="approvalBpdInstId" column="APPROVAL_BPD_INST_ID" />
<idbag name="comments" table="CR_COMMENT">
<collection-id type="long" column="COMMENT_ID">
<generator class="sequence">
<param name="sequence">CR_COMMENT_ID</param>
</generator>
</collection-id>
<key column="REQ_ID" />
<composite-element class="Comment">
<property name="createTs" column="CREATE_TS" type="calendar" access="field" update="false" insert="false" generated="insert" />
<property name="sectionId" column="SECTION_ID" />
<property name="userId" column="USER_ID" />
<property name="teamId" column="TEAM_ID" />
<many-to-one name="approvalAction" column="APPROVAL_ACTION_ID" fetch="join"
class="com.dummyCompany.ittoolkit.ws.code.ApprovalAction" />
<many-to-one name="implStatus" column="IMPL_STATUS_ID" fetch="join"
class="com.dummyCompany.ittoolkit.ws.code.ImplStatus" />
<property name="text" column="TEXT"/>
</composite-element>
</idbag>
</class>
</hibernate-mapping>
Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.htmlCode: