-->
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: My solution to the lazy-load-closed-session problem
PostPosted: Thu May 12, 2005 11:08 pm 
Newbie

Joined: Thu May 12, 2005 10:43 pm
Posts: 2
Hibernate version: 3.0 (latest from CVS)

Instead of a bug report, I'd like to submit a possible solution report...

I'm building a web application where I grab objects from Hibernate, stick them into the session, and later try to display them. Like anyone else who's tried this, I've run into the dreaded uninitialized collection and uninitialized proxy exceptions. Well, I decided to customize Hibernate for my own purposes and _force_ it to work.

So, I grabbed the latest copy of Hibernate 3 from CVS and got to work hacking. Simply put, I modified the proxy & collection initializers so that if they notice that the original session was closed, they don't throw an exception, but rather get a new session from the session factory (which was stored in the original session, so it is available), bind the proxy to the new session, use that session to read the initialize the proxy, then disconnect/close the internal session.

My solution probably has bugs (since I don't really know what I'm doing as I'm messing with the Hibernate code), but it seems to work in my preliminary tests. Of course, I have no clue if it would work in a high-load multi-threaded environment... haven't gotten that far in my testing yet.

Also, because the "session" objects (which contain the necessary SessionFactory) contained in the proxies are "transient", they won't survive in a clustered environment. I haven't yet figured out a solution to that issue. Maybe something like the "Current Contextual Sessions" that Steve wrote about on the hibernate developer's blog might be helpful to solve that one... http://blog.hibernate.org (April 12, 2005)

Still, in spite of these issues, I figured that the concept might be interesting to some people here, since this seems to be a somewhat common problem.

I only needed to modify the initialize() methods in AbstractPersistentCollection and AbstractLazyInitializer. The "patch" file is pretty short. Anybody want it? Anybody want to perfect the concept and submit it to JIRA? I feel that I'm too new here (this is my first post, actually), and I don't really have the time to finish the code at the moment.

-Nathan Kopp


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 11:15 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
I would definitely be interested in this!


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.