error
when i am going to enrering data into associate table(order items table)
following error is occured. but the other tables are inserted successfully.
In a my OrderItem table form , i created a two combo boxes for selecting productid and orderid . combo boxes are working, data from product and order tables display successfully
problem is can not insert data in to order item table
this is the error occurs
hei errornet.sf.hibernate.PropertyValueException: not-null property references a null or transient value: test.hibernate.data.Order.oname
orders table
id (PK)
oname
order_date
price _total
order_items table
id(PK)
order_id
product_id
amount
price
here is my mapping
order.hbm.xml
<set name="orderItems" table="items" inverse="true" cascade="all" lazy="false" sort="unsorted" batch-size="1" outer-join="auto">
<key column="order_id" />
<one-to-many class="test.hibernate.data.OrderItem" />
</set>
here is my orderitem.hbm.xml
<many-to-one name="order" class="test.hibernate.data.Order" cascade="all" column="order_id" not-null="true" />
some codes from order.java
public class Order {
private Set orderItems = new HashSet();
public void addOrderItem(OrderItem i){
i.setOrder(this);
orderItems.add(i);
}
public void setOrderItems(Set set) {
orderItems = set;}
some codes from orderItem.java
public class OrderItem {
public void setOrder(Order order) {
this.product = product;}
this is the code for entering data into the orderitems table
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
Order o=new Order();
OrderItem event = new OrderItem();
event.setOrder(o);
o.addOrderItem(event);
event.setOrderId(name);
event.setProductId(pname);
event.setAmount(amount);
event.setPrice(priceTotal);
sess.save(event);
sess.flush();
here is my jsp code for orderitem data entering form
still i couldn't resolve my problwm,pla any one help me to find the mistake.
|