-->
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.  [ 5 posts ] 
Author Message
 Post subject: Lazy or Non-Lazy at Runtime
PostPosted: Fri May 07, 2004 11:32 am 
Newbie

Joined: Mon Apr 26, 2004 5:17 pm
Posts: 13
I'm not sure if I understood the lazy thing in hibernate.

My idea is like this that i can find my orders from primary Table and send it to the view in a searchresult List.

The user decides which order he want's to see. At this time I want to load the whole order with it's childrens. For example a SupplierId.

In the searchresult i only want to see the supplierId while in the detail view i'd like to see the supplier details got by the supplier table.

mapping between order and supplier is many to one. One order can have o supplier. A supplier can be in many orders.

My Idea was that there is something like loadLazy and LoadFull.

Any Answer is welcome!

Thanks, Christian


P.S. Not Using the ViewSession Pattern...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 1:47 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Typically Lazy initialization would be helpful in a many-to-one,one-to-many bi-directional relation.

To take your example, you have 3 entities here:

User
Order
Supplier

User and Order share a 1-to-many relation
Order and Supplier share a 1-1 relation

Let's say that a user want's to look at all his orders, you do a load on the User (with the userid or some selection criteria).

You User Object would have a collection that would represent the Orders that the user has.

In your Hibernate mapping say we define something like this:

Code:
<class name="User"...>
<set cascade="all" inverse="true" lazy="true" name="orders" table="ACMS_CPTR_ENC_DETAILS">
   <key column="userId"/>
   <one-to-many class="UserOrder"/>
  </set>
..
</class>


When you do a session.load() or find(), the user object's collection would be populated only with Proxies to the UserOrder object and would not load the properties of the UserOrder.

Once you select the order, you selectively load the UserOrder from the collection using the collection's accessor methods, at this point, it would load and populate the properties of the UserOrder entity that you are trying to show to the user.

The supplier as part of the Order would also work in a similar fashion.

You can set the "hibernate.show_sql" property to "true" to find the difference.

Hope that helps. I am also a beginner to Hibernate and hoping that a more advanced user would give me a better explanation.

-Anand


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 2:21 am 
Newbie

Joined: Mon Apr 26, 2004 5:17 pm
Posts: 13
Ah ok. And this works also if I load the second part in a different Session?

Like the example i've written above. First comes a searchresult of orders with lazy initialization. This happens in one session and gets rendered through html to the client.

In the second session when the user selected which order he wants, then i pull out the order of the collection and its completly initialized?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 11:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You need to reattach the first object to achieve that in a different session

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 3:30 pm 
Newbie

Joined: Mon Apr 26, 2004 5:17 pm
Posts: 13
Ah thanks... now I found the page http://www.hibernate.org/hib_docs/refer ... pdate-lock
in the documentation. I'll try this out. further questions may follow ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.