2 solutions I found at hibernate users group
http://forum.hibernate.org/viewtopic.php?t=938083&sid=3e74c7e9a3aa83e9cde5ce4862c920fb

.assuming you will be retrieving a userID from your User class..
do an 'eager fetch' instead of lazy fetch e.g.

user = (User) session.createCriteria(User.class)
   .setFetchMode("groups", FetchMode.EAGER)
   .add(Expression.eq("userID", new Integer(userID)))
   .uniqueResult();

OR
In the case where you have nothing to return
add the item (userID) to the User class AND actively initialise hibernate to apprise it of the new item's addition user = (User) session.createCriteria(User.class).add(Expression.eq("userID", new Integer(userID))).uniqueResult();
Hibernate.initialize(user.getGroups());

HTH,
Martin-

----- Original Message ----- From: "Martin Ravell" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <user@struts.apache.org>; "'Martin Gainty'" <[EMAIL PROTECTED]>
Sent: Thursday, October 06, 2005 10:14 AM
Subject: RE: Premature Session Close


Hi Martin,

Thanks for the post. Yep this is one of the main sites I have referenced in
trying to get this stuff up and running.

BTW. I mentioned a log file in the first post and then forgot to attach it.
Here it is on this email.

I wonder if the
org.springframework.transaction.support.TransactionSynchronizationManager is
somehow involved? Its either that or
org.springframework.orm.hibernate.SessionFactoryUtils.

Trouble is I do not understand the mechanisms where these classes get called
from.



Regards
Marty


-----Original Message-----
From: Martin Gainty [mailto:[EMAIL PROTECTED]
Sent: Thursday, 6 October 2005 11:57 PM
To: Struts Users Mailing List
Subject: Re: Premature Session Close

Martin/Werner

Have you had a chance to look at Karl Blaums Lacy Initialization and the
DAO
Pattern with Hibernate and Spring example
http://www.jroller.com/comments/kbaum/Weblog/orm_lazy_initialization_with_d
ao

Martin-

----- Original Message ----- From: "Werner Punz" <[EMAIL PROTECTED]>
To: <user@struts.apache.org>
Sent: Thursday, October 06, 2005 8:48 AM
Subject: Re: Premature Session Close


I ran into a situation like that once, the application was using iframes
internally which triggered other sessions...

Werner


Martin Ravell wrote:
I'm running Struts, Tiles, Hibernate 2 and Spring in my project and have
been attempting for some time to get the OpenSessionInView pattern to
work
without much luck.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to