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