-->
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: Why I am loosing Database reference
PostPosted: Thu Mar 24, 2005 5:28 pm 
Newbie

Joined: Thu Mar 24, 2005 5:19 pm
Posts: 1
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:3.1[/b]

[b]Mapping documents:<hibernate-mapping>
<class name="Customer" table="customers">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<set name="orders" [color=red][u]inverse ="true"[/u][/color] lazy="true">
<key column="customer_id"/>
<one-to-many class="Order"/>
</set>
</class>[/b]

[b]Code between sessionFactory.openSession() and session.close():Transaction tx = session.beginTransaction();
Customer customer = (Customer)session.load(Customer.class,cust);
HashMap orderItem = orderItems;
Set keys = orderItem.keySet();
Iterator itr = keys.iterator();
List listItem = new ArrayList();

while(itr.hasNext()){
Long itemNo = (Long)itr.next();
Product prd = (Product)session.load(Product.class,itemNo);
Integer qty = (Integer)orderItem.get(itemNo);
LineItem lineitem = new LineItem(prd,qty);
listItem.add(lineitem);
}
Date date = Calendar.getInstance().getTime();
Order order = new Order(date);
order.setLineItems(listItem);
Set customerOrder = new HashSet();
customerOrder.add(order);
customer.setOrders(customerOrder);
session.save(order);
session.save(customer);
tx.commit();[/b]

___________________________________________________________


Hi in above shown mapping file IF I remove Lazy = true then follwoing this is happening..


Suppose first time

Customer has 1 order and that order has 3 line item

customer 1 --- Order 1--- Line Item 1 and Lien Item 2

When I tried to order second order for Same cusomer again with above code

customer 1 --- Order 2--- Line Item 1 and Lien Item 2

But See what happen to my First row it loose reference to Customer
customer 1 --- [b][u]null [/u][/b]--- Line Item 1 and Lien Item 2

[color=red][/color]

When I make Inverse = true in mapping file then it is working fine ..

[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2005 8:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
http://www.hibernate.org/hib_docs/reference/en/html/example-parentchild.html


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.