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