-->
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.  [ 13 posts ] 
Author Message
 Post subject: Automatic Reloading of Subgraph ?
PostPosted: Mon Sep 06, 2004 2:29 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
Say, I load a graph of objects. Then I process the graph. Next, I release one or more subgraphs for garbage collection. Is there any way hibernate can sync with the database and reload the subgraph again whenever needed wihout me explicitly telling it to do so? If yes, then does it have to be in the same session or it can work across sessions? What do I need to do to achieve that ?

thanks so much.
sanjib


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 8:37 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
If it is already discussed in the hibernate in action book, could you please point out to the right chapter.

The idea is to save the root object in one httpsession and then get it in the next request and process. I want to have a control on how much data i want to save in the httpsession. So, I guess, this makes sense if this works across hibernate sessions.

Is there any other way to achieve the same ?

thanks...sanjib


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 8:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Chapters 4, 5, 7 and 8 :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 9:00 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
Thanks Christian for your quick reply.

I went thru most of all chapters but couldn't figure it out how after reading a subgraph and unloading it, then initialize the subgraph again in the next hibernate session. I am using detached persistent objects(8.2.3) with Lazy loading.

I could see a method initializeCollection on session impl, but that is not exposed in the session interface. Could you please be a little more specific on which section(s) this is discussed.

thanks for your patience.
sanjib


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 9:04 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Your question is too generic, I can't help you if you don't show the things in the red box or explain your problem with a very trivial example.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 9:26 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
thanks for continuing the discussion.

Let me explain with an example.

I have Order and LineItem with 1->M relationship. Order object has a SET of LineItems. I have this association set as Lazy loading.

In one request, I retrieve a specific Order along with the LineItem and process them. Once I have done, I close the hibernate session, making the Order object as detached entity. Then I save the Order in httpsession. But I donot want to save the LineItem in httpsession along with it because I may or may not use the LineItem later and I donot want to unnecessary load httpsession. So, I want to unload the LineItem SET from the Order object before storing in httpsession.

Later, if I need to access LineItem, I should be able to get the Order from httpsession, attach it with a new hibernate session and initialize the LineItem SET ( transparently to the application) before accessing them.

I am using servlet filter to open hibernate session.

Let me know if this makes sense.

thanks...sanjib


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 10:58 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This works as expected, but it is not possible to "unload" or to get the proxy again instead of the loaded entities (LineItems). You could execute an additional query (HQL, Criteria) and store the explicetely lazy result in the HttpSession, but this seems awkward.

If HttpSession size is your concern use the "Hard Way" described in chapter 8 (storing only the Order ID and manually refreshing plus version check). If you accept bigger HttpSessions, use Detached Objects or Long Session and keep an eye on your graphs. I don't know if mixing these strategies is a good idea, but it might be neccessary in moderately complex applications.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 11:29 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
thanks for your reply.

I am going with Detached object and keeping an eye on the graph.

However, I am concerned if there is any problem with bigger HttpSession tomorrow, I should be able to solve the problem without too much code changes. "Hard Way" is really a hard way with noisy code all over the place.

It would have been nice to have the feature with some hibernate setting or some generic code(in a filter/interceptor). For example, SessionImpl class has this method "initializeCollection" that "apparently" does the job but it is not exposed in Session interface.
I am not sure if it breaks any conceptual integrity in hibernate though.

thanks...sanjib


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 11:33 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are probably thinking about Hibernate.initialize(), which does the opposite of what you want to achive: it loads an unloaded entity/collection.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 3:58 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
Yes, that's right.

I was thinking of calling removeAll on the Collection when I need to "unload" and later when I need to reload again, I pass the collection to session.initializeCollection() to get it reloaded again.

thanks...sanjib


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 5:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I was thinking of calling removeAll on the Collection when I need to "unload"

don't do that!

I pass the collection to session.initializeCollection() to get it reloaded again

There is no initializeCollection() method on net.sf.hibernate.Session!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 6:56 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
sanjibkg wrote:

However, I am concerned if there is any problem with bigger HttpSession tomorrow, I should be able to solve the problem without too much code changes. "Hard Way" is really a hard way with noisy code all over the place.



This is not the hard way, this is very easy and scalable, it is possible to write this code wothout any noise, just wrapp HttpRequest:

Code:
request.getOrder()


Is it noisy ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 7:42 am 
Newbie

Joined: Mon May 31, 2004 8:31 am
Posts: 9
Gavin,

thanks for your reply.

Yup, I am NOT going to do that. It seems Hibernate Set implementation keeps the snapshot internally and I can easily get into some inconsistent state. Moreover initializeCollection is not in the Session interface but in the implementation class and it is not meant to be used this way.

In any case, I was wondering if it makes sense to have the feature. That way, I dont have to go "hard way"(8.2.2 in HIA) and choose "detached objects" as long as I have some control how much data I want to keep in HttpSession. The issue with detached object is not so much how big HttpSession can become, but the fact that I donot have much control on it unless I keep an eye on the object graph and that is not scalable. If, for some reason, HttpSession size becomes a problem late in the development, I cannot quickly switch to other model. If we had the feature, it would have been easier to deal with the situation. Am I making sense ?


Baliukas,

thanks for your reply.

However, I am not able to follow you. In the "hard way", I have to manually make sure that the data is not stale. If I have an AGGREGATE domain object with some of dependent entites, I need to manually check every one of them right along with business logic and that is noisy.

thanks...sanjib


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