-->
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.  [ 2 posts ] 
Author Message
 Post subject: father added to db but not his child
PostPosted: Fri Jun 18, 2004 8:51 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi,

I have a one-to-many one directional relation:
Product 1-------->* ProductAttribut

in my code i made :

Product pd = new Product(pk,"CU");
ProductAttribut pa = new ProductAttribut(.....);
pd.addProductAttribute(pa);

session.saveOrUpdate(pd);
session.flush();
session.connection().commit();

on the console i see
insert into PRODUCTS (LN_SUPPLIER, ........
update PRODUCT_ATTRIBUTES set DT_UPDATE=?,

So the product it's added but not the ProductAttribute

What do i have to do to see un insert into produt_attriutes ?

i would like to see something like that
insert into PRODUCTS (LN_SUPPLIER, ........
INSERT INTO PRODUCT_ATTRIBUTES.....
update PRODUCT_ATTRIBUTES set DT_UPDATE=?,...

Here are the mapping files:

Product

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

<hibernate-mapping>



<class
name="com.influe.asp.product.hibernate.Product"
table="PRODUCTS"
>
<composite-id name="comp_id" class="com.influe.asp.product.hibernate.ProductPK">
<key-property name="LN" column="LN" type="java.lang.String"/>
<key-property name="NC_LN_COD_TYP" column="NC_LN_COD_TYP" type="java.lang.String"/>
<key-property name="PN" column="PN" type="java.lang.String"/>
<key-property name="NC_PN_COD_TYP" column="NC_PN_COD_TYP" type="java.lang.String"/>
<key-property name="PV" column="PV" type="java.lang.String"/>
</composite-id>
<property
name="LN_SUPPLIER"
type="java.lang.String"
column="LN_SUPPLIER"
length="20"
/>

<!-- one-directional one-to-many association to ProductAttribut -->
<set
name="productAttributs"
lazy="true"
inverse="true"
cascade = "all"
>
<key>
<column name="LN" />
<column name="NC_LN_COD_TYP" />
<column name="PN" />
<column name="NC_PN_COD_TYP" />
<column name="PV" />
</key>
<one-to-many
class="com.influe.asp.product.hibernate.ProductAttribut"
/>
</set>


</class>
</hibernate-mapping>



ProductAttribute XML

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

<hibernate-mapping>


<class
name="com.influe.asp.product.hibernate.ProductAttribut"
table="PRODUCT_ATTRIBUTES"
>
<composite-id name="comp_id" class="com.influe.asp.product.hibernate.ProductAttributPK">
<key-property name="FIELD" column="FIELD" type="java.lang.String"/>
<key-property name="LN" column="LN" type="java.lang.String"/>
<key-property name="NC_LN_COD_TYP" column="NC_LN_COD_TYP" type="java.lang.String"/>
<key-property name="PN" column="PN" type="java.lang.String"/>
<key-property name="NC_PN_COD_TYP" column="NC_PN_COD_TYP" type="java.lang.String"/>
<key-property name="PV" column="PV" type="java.lang.String"/>
</composite-id>

<property
name="DT_UPDATE"
type="java.sql.Timestamp"
column="DT_UPDATE"
not-null="true"
length="7"
</class>
</hibernate-mapping>


Here are the java files:

Product.java


Thank's a lot

Ady


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 18, 2004 9:04 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
I found the solution.
The key is :
#If a parent is saved, all children are passed to saveOrUpdate()

#If a parent is passed to update() or saveOrUpdate(), all children are passed to saveOrUpdate()


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