-->
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.  [ 1 post ] 
Author Message
 Post subject: How do I insert only new rows in a collection?
PostPosted: Tue Apr 17, 2007 2:03 am 
Beginner
Beginner

Joined: Thu Oct 13, 2005 3:40 pm
Posts: 29
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

Mapping documents:
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>


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.html

[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.