Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Hibernate 3.1 Updates then deletes children, do not want thi
PostPosted: Mon Jun 04, 2012 11:23 am 
Newbie

Joined: Tue Jul 28, 2009 1:31 pm
Posts: 4
I am working with hibernate 3.1 and I am having some very strange behaviors with my children

Here is my mapping for the parent:

Code:
<class name="LaborRateReq" schema="Z1BJ001$" table="LBR_RATE_REQ" mutable="true">
    <id name="reqIDSeqKey" column="REQ_ID_SEQ_KEY" type="java.lang.Long" length="9">
        <generator class="identity" />
    </id>
    <property name="reqStatNm" column="REQ_STAT_NM" type="java.lang.String" not-null="true" length="20" />
    <property name="orgCupid" column="ORG_CUPID" type="java.lang.String" not-null="true" length="10" />
    ...     
    <property name="updtUserID" column="LAST_UPDT_CUPID" type="java.lang.String" length="10" />
    <property name="updtUserTmstmp" column="LAST_UPDT_TS" type="timestamp" length="26" />


    <set name="reqDealerObjs" inverse="true" lazy="false" cascade="all-delete-orphan">
        <key>
            <column name="REQ_ID_SEQ_KEY" not-null="true" />
        </key>
        <one-to-many class="DealerList" />
    </set> 
</class>


The following is a mapping of the child:

Code:
<class name="DealerList" schema="Z1BJ001$" table="LBR_FORM_DLR_LIST" mutable="true">
    <composite-id name="primaryKey" class="DealerListKey">
        <key-property name="reqIDSeqKey" column="REQ_ID_SEQ_KEY" type="java.lang.Long" />
        <key-property name="busType" column="BUS_TYP_CD" type="java.lang.String" length="2" />
        <key-property name="dlrCd" column="DLR_CD" type="java.lang.String" length="6" />
    </composite-id>

    <property name="crteTS" column="CRTE_TS" type="timestamp" length="26" />
    <property name="updtUserID" column="LAST_UPDT_CUPID" type="java.lang.String" length="10" />
    <property name="updtUserTmstmp" column="LAST_UPDT_TS" type="timestamp" length="26" />

    <many-to-one name="parent" column="REQ_ID_SEQ_KEY" class="LaborRateReq" insert="false" update="false" not-null="true" />
</class>


This problem is that hibernate is deleting my children, I do not want them deleted - even stranger it is UPDATING them then deleting... any idea?

The log:
Code:
[6/4/12 9:18:29:393 CDT] 00000030 SystemOut     O Hibernate: select laborrater0_.REQ_ID_SEQ_KEY as REQ1_18_1_, laborrater0_.REQ_STAT_NM as REQ2_18_1_, laborrater0_.ORG_CUPID as ORG3_18_1_, laborrater0_.ORG_AFLTN_CD as ORG4_18_1_, laborrater0_.ORG_DT as ORG5_18_1_, laborrater0_.PRELM_APRV_CUPID as PRELM6_18_1_, laborrater0_.PRELM_APRV_AFLTN_CD as PRELM7_18_1_, laborrater0_.PRELM_APRV_DT as PRELM8_18_1_, laborrater0_.DIST_MGR_CUPID as DIST9_18_1_, laborrater0_.DIST_MGR_AFLTN_CD as DIST10_18_1_, laborrater0_.DIST_MGR_APRV_DT as DIST11_18_1_, laborrater0_.WAR_APRV_CUPID as WAR12_18_1_, laborrater0_.WAR_APRV_AFLTN_CD as WAR13_18_1_, laborrater0_.WAR_APRV_DT as WAR14_18_1_, laborrater0_.REJ_CUPID as REJ15_18_1_, laborrater0_.REJ_AFLTN_CD as REJ16_18_1_, laborrater0_.REJ_DT as REJ17_18_1_, laborrater0_.CCY_CD as CCY18_18_1_, laborrater0_.STAT_CD as STAT19_18_1_, laborrater0_.BSE_RATE as BSE20_18_1_, laborrater0_.NEW_BSE_PCT_PREV_BSE as NEW21_18_1_, laborrater0_.SELL_RATE as SELL22_18_1_, laborrater0_.COST_TYP as COST23_18_1_, laborrater0_.COST_PCT as COST24_18_1_, laborrater0_.COST_RATE as COST25_18_1_, laborrater0_.TRAV_TYP as TRAV26_18_1_, laborrater0_.TRAV_PCT as TRAV27_18_1_, laborrater0_.TRAV_RATE as TRAV28_18_1_, laborrater0_.VEH_TYP as VEH29_18_1_, laborrater0_.VEH_PCT as VEH30_18_1_, laborrater0_.VEH_RATE as VEH31_18_1_, laborrater0_.SHOP_SUPP_TYP as SHOP32_18_1_, laborrater0_.SHOP_SUPP_PCT as SHOP33_18_1_, laborrater0_.SHOP_SUPP_RATE as SHOP34_18_1_, laborrater0_.ACT_SHOP_SUPP_PCT as ACT35_18_1_, laborrater0_.DISP_TYP as DISP36_18_1_, laborrater0_.DISP_PCT as DISP37_18_1_, laborrater0_.DISP_RATE as DISP38_18_1_, laborrater0_.ACT_DISP_PCT as ACT39_18_1_, laborrater0_.AVG_REAL_RATE as AVG40_18_1_, laborrater0_.AVG_REAL_PCT as AVG41_18_1_, laborrater0_.PRPSD_EFF_DT as PRPSD42_18_1_, laborrater0_.RATE_EFF_DT as RATE43_18_1_, laborrater0_.TERM_EFF_DT as TERM44_18_1_, laborrater0_.ANAL_BEG_DT as ANAL45_18_1_, laborrater0_.ANAL_END_DT as ANAL46_18_1_, laborrater0_.VEH_RPTG_UNITS as VEH47_18_1_, laborrater0_.STRGHT_TM_RVNU as STRGHT48_18_1_, laborrater0_.XTRNL_RVNU_HR as XTRNL49_18_1_, laborrater0_.SVC_HR as SVC50_18_1_, laborrater0_.SHOP_SUPP_COSTS as SHOP51_18_1_, laborrater0_.DISP_FEES as DISP52_18_1_, laborrater0_.DISP_RCVRY as DISP53_18_1_, laborrater0_.PREV_POST_RATE as PREV54_18_1_, laborrater0_.NEW_POST_RATE as NEW55_18_1_, laborrater0_.CMNT as CMNT18_1_, laborrater0_.LAST_UPDT_CUPID as LAST57_18_1_, laborrater0_.LAST_UPDT_TS as LAST58_18_1_, reqdealero1_.REQ_ID_SEQ_KEY as REQ1_3_, reqdealero1_.BUS_TYP_CD as BUS2_3_, reqdealero1_.DLR_CD as DLR3_3_, reqdealero1_.REQ_ID_SEQ_KEY as REQ1_19_0_, reqdealero1_.BUS_TYP_CD as BUS2_19_0_, reqdealero1_.DLR_CD as DLR3_19_0_, reqdealero1_.CRTE_TS as CRTE4_19_0_, reqdealero1_.LAST_UPDT_CUPID as LAST5_19_0_, reqdealero1_.LAST_UPDT_TS as LAST6_19_0_ from Z1BJ001$.LBR_RATE_REQ laborrater0_ left outer join Z1BJ001$.LBR_FORM_DLR_LIST reqdealero1_ on laborrater0_.REQ_ID_SEQ_KEY=reqdealero1_.REQ_ID_SEQ_KEY where laborrater0_.REQ_ID_SEQ_KEY=? WITH UR
[6/4/12 9:18:29:408 CDT] 00000030 SystemOut     O Hibernate: select dealerlist0_.REQ_ID_SEQ_KEY as REQ1_19_0_, dealerlist0_.BUS_TYP_CD as BUS2_19_0_, dealerlist0_.DLR_CD as DLR3_19_0_, dealerlist0_.CRTE_TS as CRTE4_19_0_, dealerlist0_.LAST_UPDT_CUPID as LAST5_19_0_, dealerlist0_.LAST_UPDT_TS as LAST6_19_0_ from Z1BJ001$.LBR_FORM_DLR_LIST dealerlist0_ where dealerlist0_.REQ_ID_SEQ_KEY=? and dealerlist0_.BUS_TYP_CD=? and dealerlist0_.DLR_CD=? WITH UR
[6/4/12 9:18:29:408 CDT] 00000030 SystemOut     O Hibernate: select dealerlist0_.REQ_ID_SEQ_KEY as REQ1_19_0_, dealerlist0_.BUS_TYP_CD as BUS2_19_0_, dealerlist0_.DLR_CD as DLR3_19_0_, dealerlist0_.CRTE_TS as CRTE4_19_0_, dealerlist0_.LAST_UPDT_CUPID as LAST5_19_0_, dealerlist0_.LAST_UPDT_TS as LAST6_19_0_ from Z1BJ001$.LBR_FORM_DLR_LIST dealerlist0_ where dealerlist0_.REQ_ID_SEQ_KEY=? and dealerlist0_.BUS_TYP_CD=? and dealerlist0_.DLR_CD=? WITH UR
[6/4/12 9:18:29:424 CDT] 00000030 SystemOut     O Hibernate: select dealerlist0_.REQ_ID_SEQ_KEY as REQ1_19_0_, dealerlist0_.BUS_TYP_CD as BUS2_19_0_, dealerlist0_.DLR_CD as DLR3_19_0_, dealerlist0_.CRTE_TS as CRTE4_19_0_, dealerlist0_.LAST_UPDT_CUPID as LAST5_19_0_, dealerlist0_.LAST_UPDT_TS as LAST6_19_0_ from Z1BJ001$.LBR_FORM_DLR_LIST dealerlist0_ where dealerlist0_.REQ_ID_SEQ_KEY=? and dealerlist0_.BUS_TYP_CD=? and dealerlist0_.DLR_CD=? WITH UR
[6/4/12 9:18:29:424 CDT] 00000030 SystemOut     O Hibernate: update Z1BJ001$.LBR_RATE_REQ set REQ_STAT_NM=?, ORG_CUPID=?, ORG_AFLTN_CD=?, ORG_DT=?, PRELM_APRV_CUPID=?, PRELM_APRV_AFLTN_CD=?, PRELM_APRV_DT=?, DIST_MGR_CUPID=?, DIST_MGR_AFLTN_CD=?, DIST_MGR_APRV_DT=?, WAR_APRV_CUPID=?, WAR_APRV_AFLTN_CD=?, WAR_APRV_DT=?, REJ_CUPID=?, REJ_AFLTN_CD=?, REJ_DT=?, CCY_CD=?, STAT_CD=?, BSE_RATE=?, NEW_BSE_PCT_PREV_BSE=?, SELL_RATE=?, COST_TYP=?, COST_PCT=?, COST_RATE=?, TRAV_TYP=?, TRAV_PCT=?, TRAV_RATE=?, VEH_TYP=?, VEH_PCT=?, VEH_RATE=?, SHOP_SUPP_TYP=?, SHOP_SUPP_PCT=?, SHOP_SUPP_RATE=?, ACT_SHOP_SUPP_PCT=?, DISP_TYP=?, DISP_PCT=?, DISP_RATE=?, ACT_DISP_PCT=?, AVG_REAL_RATE=?, AVG_REAL_PCT=?, PRPSD_EFF_DT=?, RATE_EFF_DT=?, TERM_EFF_DT=?, ANAL_BEG_DT=?, ANAL_END_DT=?, VEH_RPTG_UNITS=?, STRGHT_TM_RVNU=?, XTRNL_RVNU_HR=?, SVC_HR=?, SHOP_SUPP_COSTS=?, DISP_FEES=?, DISP_RCVRY=?, PREV_POST_RATE=?, NEW_POST_RATE=?, CMNT=?, LAST_UPDT_CUPID=?, LAST_UPDT_TS=? where REQ_ID_SEQ_KEY=?
[6/4/12 9:18:29:424 CDT] 00000030 SystemOut     O Hibernate: update Z1BJ001$.LBR_FORM_DLR_LIST set CRTE_TS=?, LAST_UPDT_CUPID=?, LAST_UPDT_TS=? where REQ_ID_SEQ_KEY=? and BUS_TYP_CD=? and DLR_CD=?
[6/4/12 9:18:29:440 CDT] 00000030 SystemOut     O Hibernate: update Z1BJ001$.LBR_FORM_DLR_LIST set CRTE_TS=?, LAST_UPDT_CUPID=?, LAST_UPDT_TS=? where REQ_ID_SEQ_KEY=? and BUS_TYP_CD=? and DLR_CD=?
[6/4/12 9:18:29:440 CDT] 00000030 SystemOut     O Hibernate: update Z1BJ001$.LBR_FORM_DLR_LIST set CRTE_TS=?, LAST_UPDT_CUPID=?, LAST_UPDT_TS=? where REQ_ID_SEQ_KEY=? and BUS_TYP_CD=? and DLR_CD=?
[6/4/12 9:18:29:440 CDT] 00000030 SystemOut     O Hibernate: delete from Z1BJ001$.LBR_FORM_DLR_LIST where REQ_ID_SEQ_KEY=? and BUS_TYP_CD=? and DLR_CD=?
[6/4/12 9:18:29:455 CDT] 00000030 SystemOut     O Hibernate: delete from Z1BJ001$.LBR_FORM_DLR_LIST where REQ_ID_SEQ_KEY=? and BUS_TYP_CD=? and DLR_CD=?
[6/4/12 9:18:29:455 CDT] 00000030 SystemOut     O Hibernate: delete from Z1BJ001$.LBR_FORM_DLR_LIST where REQ_ID_SEQ_KEY=? and BUS_TYP_CD=? and DLR_CD=?


Top
 Profile  
 
 Post subject: Re: Hibernate 3.1 Updates then deletes children, do not want thi
PostPosted: Mon Jun 04, 2012 2:48 pm 
Beginner
Beginner

Joined: Mon Jun 04, 2012 12:31 pm
Posts: 20
Your parent object needs to specify a different cascade. I think what you want is the value "all".

Please look here for more information: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/example-parentchild.html#example-parentchild-cascades


Top
 Profile  
 
 Post subject: Re: Hibernate 3.1 Updates then deletes children, do not want thi
PostPosted: Mon Jun 04, 2012 3:45 pm 
Newbie

Joined: Tue Jul 28, 2009 1:31 pm
Posts: 4
reynolr, If I do that the child entities are not deleted when I remove them from the collection.


Top
 Profile  
 
 Post subject: Re: Hibernate 3.1 Updates then deletes children, do not want thi
PostPosted: Mon Jun 04, 2012 7:02 pm 
Beginner
Beginner

Joined: Mon Jun 04, 2012 12:31 pm
Posts: 20
davemk wrote:
reynolr, If I do that the child entities are not deleted when I remove them from the collection.


Isn't that what you wanted?


Top
 Profile  
 
 Post subject: Re: Hibernate 3.1 Updates then deletes children, do not want thi
PostPosted: Mon Jun 04, 2012 7:25 pm 
Newbie

Joined: Tue Jul 28, 2009 1:31 pm
Posts: 4
Let me clarify, I want the children to be deleted IF they are no longer contained within the set during a merge. However, all the records that remain in the set I would like left intact on the database, Hibernate seems to just purge everything.

The first time I update the parent (with no children) it creates the children just fine, then if I update the record again without changing the children the children are erased. I update the parent a third time (still changing nothing) and the children are re created.


Top
 Profile  
 
 Post subject: Re: Hibernate 3.1 Updates then deletes children, do not want thi
PostPosted: Mon Jun 04, 2012 7:57 pm 
Beginner
Beginner

Joined: Mon Jun 04, 2012 12:31 pm
Posts: 20
You're going to have to post the code you're using to accomplish this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

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.