-->
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: why i cannot insert but update
PostPosted: Mon May 17, 2004 9:07 am 
Newbie

Joined: Thu Apr 29, 2004 11:15 pm
Posts: 8
when i user the code:
Product p=new Product(...);
Order.addProduct(p)
sess = sf.openSession();
Transaction t = sess.beginTransaction();
sess.save(order);
t.commit();
sess.close();

there is no exception but only update the date in orderitem table
it cannot insert the date to this table.
please give me a advice.
thanks.

the method addProduct in Order is
public void addProduct(Product p) {
Orderitem oi=new Orderitem(p,this);
this.orderitem.add(oi);


}


mapping files:

<class name="test.hibernate.Order" table="orders">
<id name="id" type="string" unsaved-value="null" >
<column name="id"
not-null="true"/>
</id>
<property name="date">
<column name="order_date" not-null="true"/>
</property>

<property name="priceTotal">
<column name="price_total" not-null="true"/>
</property>

<set name="orderItems" table="order_items" inverse="true" cascade="all">
<key column="order_id" />
<one-to-many class="test.hibernate.OrderItem" />
</set>
</class>
<class name="test.hibernate.Product" table="products">
<id name="id" type="string" unsaved-value="null" >
<column name="id" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="name">
<column name="name"not-null="true"/>
</property>

<property name="price">
<column name="price" not-null="true"/>
</property>

<property name="amount">
<column name="amount" not-null="true"/>
</property>
</class>
<class name="test.hibernate.OrderItem" table="order_items">
<id name="id" type="string" unsaved-value="null" >
<column name="id" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="orderId" insert="false" update="false">
<column name="order_id" not-null="true"/>
</property>

<property name="productId" insert="false" update="false">
<column name="product_id" not-null="true"/>
</property>


<property name="amount">
<column name="amount" sql-type="int" not-null="true"/>
</property>


<property name="price">
<column name="price" sql-type="double" not-null="true"/>
</property>

<many-to-one name="order" class="test.hibernate.Order" column="order_id" />
<many-to-one name="product" class="test.hibernate.Product" column="product_id"/>

</class>


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.