Hi Guys,
I have some beginners issues with mapping associations, i have reference material but still would like to get peoples thoughts.
I have a table Customer_Orders, that contains order informtion
I have a table Products, that lists productions available to buy.
I then have a table called orders_products which contains, an order id, a product_id and product qty.
When i create a new order all works fine except populating the orders_products table. If i remove the product qty attribute of the table i can get the table to populate
Mapping Files below.
Code:
CustomerOrders.hbm
<set
inverse="true"
lazy="true"
name="ordersProductsSet"
table="orders_products"
>
<key column="ORDER_ID" />
<one-to-many class="OrdersProducts" />
</set>
Products.hbm
Code:
<set
inverse="true"
lazy="true"
name="ordersProductsSet"
>
<key column="PRODUCT_ID" />
<one-to-many class="OrdersProducts" />
</set>
OrdersProducts.hbm
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.egalway.estore.vo">
<class name="OrdersProducts" table="orders_products">
<composite-id class="OrdersProductsPK" name="id">
<key-many-to-one
class="Products"
column="PRODUCT_ID"
name="product"
/>
<key-many-to-one
class="CustomerOrders"
column="ORDER_ID"
name="order"
/>
</composite-id>
<property
column="PRODUCT_QTY"
length="11"
name="productQty"
not-null="false"
type="integer"
/>
</class>
</hibernate-mapping>
If anyone could point out how i can populate the orders_products table that would be great.
The following is what i am trying from the java side.
Code:
OrdersProducts op = new OrdersProducts();
op.setId(new OrdersProductsPK(p,order));
op.setProductQty(new Integer(99));
storeConfigService.saveObject(order);