Re: [appfuse-user] lazy loading impossible to set up

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: [appfuse-user] lazy loading impossible to set up

Matt Raible-3
You should be able to use the following in your DAOTest and
ManagerTest classes to keep the session open when running your tests:

protected void setUp() throws Exception {
    // the following is necessary for lazy loading
    sf = (SessionFactory) ctx.getBean("sessionFactory");
    // open and bind the session for this test thread.
    Session s = sf.openSession();
        TransactionSynchronizationManager
          .bindResource(sf, new SessionHolder(s));
 
    // setup code here
}

protected void tearDown() throws Exception {
    // unbind and close the session.
    SessionHolder holder = (SessionHolder)
        TransactionSynchronizationManager.getResource(sf);
    Session s = holder.getSession();
    s.flush();
    TransactionSynchronizationManager.unbindResource(sf);
    SessionFactoryUtils.closeSessionIfNecessary(s, sf);

    // teardown code here
}

Matt

On 7/6/05, Arthur CLEMENT <[hidden email]> wrote:

>  
> I looked the appfuse 1.7 cvs repository and compared to my files and found
> no difference!
> For the moment I'd really like the application to work and see about the
> tests afterwards. Anyway, on the dao tests when being lazy there is much
> more information, starting with this mailing list.
> But I'm still stuck with my first problem : the hibernate session is closed
> when i try to access my collection if I set lazy to true. I understand why I
> get the exception but cant manage to solve it.
> Any help really appreciated here.
>  
> Arthur
>  
>  
> ----- Original Message -----
> From: Andrew Premdas
> To: [hidden email]
> Sent: Friday, July 01, 2005 6:37 PM
> Subject: Re: [appfuse-user] lazy loading impossible to set up
>
> As far as I remember Appfuse 1.7 supported lazy loading by default. So
> really you don't have to do anything - almost...
>
> As you are using hib2 you have to specify in your xdoclet tags that the
> relationship in question is lazy (hib2 defaults to none lazy).
> e.g. @hibernate.many-to-one lazy="true"
>
> Also if you are expecting dao tests to work with lazy objects you will have
> to do some work to ensure a session is open by default it closes to early.
> I've posted about this on June 6.
>
> Finally if  that doesn't work (or you've already done all this). Tt might be
> worth checking out 1.7 from CVS and doing a diff with your app on .xml files
> to see whats changed. Hope this helps
>
> Andrew
>
>  
> On 7/1/05, Arthur CLEMENT <[hidden email]> wrote:
> >
> > Hello,
> >  
> > I've been trying to set up lazy loading in my appfuse application for the
> last 3 weeks without success.
> > I've think I've read all its possible to read in google plus the related
> messages on this list and Karls baums weblog which I thought would solve my
> problems as I have the same configuration as he describes.
> > Unfortunately I havent been able to have the OpenSessionInViewFilter not
> the interceptor to work (and I've spent quite some time trying)
> > So my question is : can somebody post his configuration or at least be
> precise on what to do to have lazy loading working with appfuse (ie using
> dao pattern and managers)?
> > I'm using appfuse 1.7 and hibernate 2 and cannot upgrade to 3 for the
> moment because I'm using also using the liferay portal (which is still in
> hibernate 2) so any solution telling me to upgrade to appfuse 1.8 does not
> interest me.
> > I'm sure many people out there must have the same problem as lazy loading
> becomes critical when your application becomes consequent.
> > Many thanks in advance.
> >  
> > Arthur
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]