Unfortunately doing an eager fetch would (if I understand the concept
correctly) be the exact opposite of what I am trying to achieve here. I
really need the load to be lazy.

Am I correct in thinking that an eager fetch is the opposite of a lazy one?
i.e. all of the associated collections are loaded with the owning object?

The second suggestion of doing an initialize is basically the same right? It
is saying to Hibernate 'go and fill this collection for this object'. i.e.
not being lazy.

What I am trying to do is use the OpenSessionInView pattern.

This means that the control of opening and closing Hibernate sessions is
delegated to a filter (or some other mechanism) which opens the session at
the start of the request, allows any objects whether they are in the DAO
layer, Action layer, even JSP layer to access hibernate objects with Lazy
loading. Therefore it should only load collections when they are first
accessed. The filter should then execute it's shutdown method at the end of
the request which will close the Hibernate session.



Regards
Marty

-----Original Message-----
From: Martin Gainty [mailto:[EMAIL PROTECTED] 
Sent: Friday, 7 October 2005 12:47 AM
To: [EMAIL PROTECTED]
Cc: Struts Users Mailing List
Subject: Re: Premature Session Close

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

.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]



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

Reply via email to