Re: [appfuse-user] FW: Spring+Hibernate Design for Session&Transaction problem

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

Re: [appfuse-user] FW: Spring+Hibernate Design for Session&Transaction problem

Matt Raible-3
Have you tried putting the following in your setUp() and tearDown()
methods of you tests to keep the session open?

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
}

On 7/20/05, Chao Tang <[hidden email]> wrote:

> I got this in my app too.  So for now, no lazy loading for me either.
>
> Chao
>
> On 7/20/05, Victor Weng <[hidden email]> wrote:
> > Yes, I got it when I tested on the DAO code.
> >
> > -----Original Message-----
> > From: Matt Raible [mailto:[hidden email]]
> > Sent: Wednesday, July 20, 2005 1:18 PM
> > To: Victor Weng
> > Subject: Re: Spring+Hibernate Design for Session&Transaction problem
> >
> > Do you get this when running a test or when you're running your app
> > through a browser?
> >
> > Matt
> >
> > P.S. In the future, please send AppFuse related e-mails to the mailing
> > list ([hidden email]) - that way the correspondence is
> > archived for future users.  If you're not subscribed, send a blank
> > e-mail to [hidden email] to subscribe.
> >
> >
> > On 7/19/05, Victor Weng <[hidden email]> wrote:
> > >
> > >
> > >
> > > Hi matt,
> > >
> > >          I have studied your project of appfuse about 1 month, and
> > it's
> > > pretty good.
> > >
> > >          And I have a problem about the hibernate session with lazy
> > load
> > > object, which would occur exception of "no session or session closed"
> > when I
> > > want to get the collection property in serviceManager. Of course I fix
> > it by
> > > setting lazy load to false, but it seems not good with lot records and
> > > complex relationships between objects.
> > >
> > > Thanks in advance.
> > >
> > > sincere,
> > >
> > > -Victor
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

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