-->
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.  [ 8 posts ] 
Author Message
 Post subject: Why Child gets updated? insted of Insert?
PostPosted: Tue Nov 08, 2005 7:23 pm 
Newbie

Joined: Fri Nov 04, 2005 3:04 pm
Posts: 15
Parent Mapping:

<hibernate-mapping package="com.inventory.vo">
<class name="WholesalerVO" table="WHLSLR" lazy="true">
<id name="wholesalerId" type="long">
<column name="WHLSLR_ID" length="15" not-null="true" />
<generator class="sequence">
<param name="sequence">BLOCK_ID_SEQ</param>
</generator>
</id>

<bag name="wsRateplanVOList" cascade="all">
<key column="WHLSLR_ID" />
<one-to-many class="WSRateplanVO" />
</bag>
</class>
</hibernate-mapping>


Child Mapping:

<hibernate-mapping
package="com.inventory.vo">

<class name="WSInventoryVO" table="WHLSLR_INV" dynamic-update="true" lazy="true">

<composite-id>
<key-many-to-one name="wholesalerVO" class="WholesalerVO">
<column name="WHLSLR_ID"/>
</key-many-to-one>
<key-property name="productId" type="long" length="15" column="PRDCT_ID"/>
<key-property name="invStartDTM" type="calendar" column="PROP_PRDT_USE_START_DTME"/>
</composite-id>
</class>

Generated SQL:
Hibernate: insert into WHLSLR (WHLSLR_ID) values (?)
Hibernate: update RATE_PLAN_INFO set WHLSLR_ID=? where WHLSLR_ID=? and RATE_PLAN_CLASS_CD=? and RATE_PLAN_CD=?


Top
 Profile  
 
 Post subject: Some confusion in your sql output?
PostPosted: Tue Nov 08, 2005 9:28 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
When you say "child", do you mean the wsRateplanVOList bag? That's not being touched. And what is the RATE_PLAN_INFO table? That's not in anywhere in the mapping you've provided. Is that the child that you're talking about? I think even the project gurus would need to see the mapping for that table before answering your question.

When you respond to this with a more complete mapping, can you use the code tag, please?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 9:49 pm 
Newbie

Joined: Fri Nov 04, 2005 3:04 pm
Posts: 15
SORRY, my bad! copied some thing worong

Here is the child mapping

<hibernate-mapping package="com.starwood.valhalla.inventory.vo">
<class name="WSRateplanVO" table="RATE_PLAN_INFO" lazy="false">


<composite-id>
<key-many-to-one name="wholesalerVO" class="WholesalerVO">
<column name="WHLSLR_ID"/>
</key-many-to-one>
<key-property name="classCode" column="RATE_PLAN_CLASS_CD" type="string"/>
<key-property name="rateplanId" column="RATE_PLAN_CD" type="string"/>
</composite-id>
</class>

</hibernate-mapping>

CODE:

// main call
boolean r = createWholesalerAll(createWholesalerVO());

// create parent
private WholesalerVO createWholesalerVO(){
// Create Parent
WholesalerVO vo = new WholesalerVO();
//create child and set child in parent
vo.setWsRateplanVOList(getRateplanVOList(vo));
return vo;
}


//create child
private static List getRateplanVOList(WholesalerVO wsvo){
// Create child and set parent in child
ArrayList list = new ArrayList();
WSRateplanVO vo = new WSRateplanVO();
vo.setClassCode("c");
vo.setRateplanId("R");
vo.setWholesalerVO(wsvo);
list.add(vo);
return list;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 9:57 pm 
Newbie

Joined: Fri Nov 04, 2005 3:04 pm
Posts: 15
Wish i could edit the post! here with code tag!
SORRY, my bad! copied some thing worong

Here is the child mapping
Code:
<hibernate-mapping package="com.inventory.vo">
<class name="WSRateplanVO" table="RATE_PLAN_INFO" lazy="false">


<composite-id>
<key-many-to-one name="wholesalerVO" class="WholesalerVO">
<column name="WHLSLR_ID"/>
</key-many-to-one>
<key-property name="classCode" column="RATE_PLAN_CLASS_CD" type="string"/>
<key-property name="rateplanId" column="RATE_PLAN_CD" type="string"/>
</composite-id>
</class>

</hibernate-mapping>


CODE:
Code:

// main call
boolean r = createWholesalerAll(createWholesalerVO());

// create parent
private WholesalerVO createWholesalerVO(){
// Create Parent
WholesalerVO vo = new WholesalerVO();
//create child and set child in parent
vo.setWsRateplanVOList(getRateplanVOList(vo));
return vo;
}


//create child
private static List getRateplanVOList(WholesalerVO wsvo){
// Create child and set parent in child
ArrayList list = new ArrayList();
WSRateplanVO vo = new WSRateplanVO();
vo.setClassCode("c");
vo.setRateplanId("R");
vo.setWholesalerVO(wsvo);
list.add(vo);
return list;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 10:15 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Thanks for the code tag :) I've compared what you've written with the closest mapping I've written. I've never used a bag, only maps, but assuming that the only difference is a non-unique id on the bag table, then what you've got looks good to me. So I'm going to have to bow out of this one, sorry: I don't have the knowledge you need.

There's no way that you could introduce a discriminator to your RATE_PLAN_INFO table so that you can get rid of the bag, is there? Or put a uniqueness constraint on the relationship between the tables? If you use a map or list, it should work: the same mapping works for me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:44 am 
Newbie

Joined: Fri Nov 04, 2005 3:04 pm
Posts: 15
tenwit wrote:
There's no way that you could introduce a discriminator to your RATE_PLAN_INFO table so that you can get rid of the bag, is there? Or put a uniqueness constraint on the relationship between the tables? If you use a map or list, it should work: the same mapping works for me.


I tried using Set, same result. I no idea whats the problem, i have similar setup for another child table it works!


Top
 Profile  
 
 Post subject: Problem solved
PostPosted: Wed Nov 09, 2005 5:28 pm 
Newbie

Joined: Fri Nov 04, 2005 3:04 pm
Posts: 15
Here is the problem

Old Mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


New Mapping
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">


I used the eclipse tool Hibernator to generate the mapping (basic mapping) which created the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 6:39 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I guess that explains why I couldn't find the problem then :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.