-->
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: 1-to-M problem
PostPosted: Tue Mar 30, 2004 5:17 am 
Beginner
Beginner

Joined: Wed Mar 24, 2004 8:43 am
Posts: 42
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.


Top
 Profile  
 
 Post subject: i nave found a solution to the 1 to M priblem
PostPosted: Wed Mar 31, 2004 1:10 am 
Beginner
Beginner

Joined: Wed Mar 24, 2004 8:43 am
Posts: 42
hi all

i have found solution

i chnaged the NewOrderItems.java as follows



Configuration cfg=new Configuration().addClass(OrderItem.class).addClass(Order.class).addClass(Product.class);

SessionFactory sf=cfg.buildSessionFactory();

Session sess=sf.openSession();

Order o=(Order)sess.load(test.hibernate.data.Order.class,name);
Product p=(Product)sess.load(test.hibernate.data.Product.class,pname);

OrderItem event = new OrderItem();
o.setOrderItems(new HashSet());
p.setProductItems(new HashSet());

event.setOrder(o);
event.setProduct(p);


event.setOrderId(name);
event.setProductId(pname);
event.setAmount(amount);
event.setPrice(priceTotal);
sess.save(event);
sess.flush();


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.