Using sessionFactory.currentSession.clear() and LazyInitializationExceptions with 1.3.x

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using sessionFactory.currentSession.clear() and LazyInitializationExceptions with 1.3.x

jondo_w
Prior to v1.3.x (we were using 1.0.x) one of the suggestions frequently seen on this ML was to use:

sessionFactory.currentSession.clear()

to preserve memory in your VM while doing heavy GORM data manipulation. We did this, usually with a flush() then a clear() at appropriate milestones and it seemed to work just fine.

However, since moving to 1.3.x (currently using 1.3.7) with the latest version of our product, the clear() method usage seems to have changed. As a result, while doing long lived transactions, when we issue a clear(), we immediately experience LazyInitializationException's and/or no Session for query etc. This is with code that has not changed since 1.0.6 usage.

So has something changed in the underlying implementation, and should we not be using clear() anymore? I'm somewhat confused now. :-S Bert, are you out there? :-)

Thanks,
Darryl Pentz
Reply | Threaded
Open this post in threaded view
|

Re: Using sessionFactory.currentSession.clear() and LazyInitializationExceptions with 1.3.x

Daniel Henrique Alves Lima
    1.3.6 works fine for me. Are you able to reproduce the issue in a
small test app?

Darryl Pentz wrote:

> Prior to v1.3.x (we were using 1.0.x) one of the suggestions
> frequently seen on this ML was to use:
>
> sessionFactory.currentSession.clear()
>
> to preserve memory in your VM while doing heavy GORM data
> manipulation. We did this, usually with a flush() then a clear() at
> appropriate milestones and it seemed to work just fine.
>
> However, since moving to 1.3.x (currently using 1.3.7) with the latest
> version of our product, the clear() method usage seems to have
> changed. As a result, while doing long lived transactions, when we
> issue a clear(), we immediately experience
> LazyInitializationException's and/or no Session for query etc. This is
> with code that has not changed since 1.0.6 usage.
>
> So has something changed in the underlying implementation, and should
> we not be using clear() anymore? I'm somewhat confused now. :-S Bert,
> are you out there? :-)
>
> Thanks,
> Darryl Pentz

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Using sessionFactory.currentSession.clear() and LazyInitializationExceptions with 1.3.x

burtbeckwith
In reply to this post by jondo_w
Hibernate was upgraded from 3.2.6 to 3.3.1 so there must have been a change there - it's unlikely to be related to Grails since you're working directly with the Session.

clear() unsets the Session from proxies and collections in addition to removing cache references to everything, so it makes sense that you'd see that.

You could either explicitly initialize the collections before calling clear() - this would cause temporary jumps in memory usage but would be reset after the clear() - or try/catch access to lazy-loaded collections and re-attach when you get a LIE.

Burt

> Prior to v1.3.x (we were using 1.0.x) one of the suggestions frequently seen on
> this ML was to use:
>
> sessionFactory.currentSession.clear()
>
> to preserve memory in your VM while doing heavy GORM data manipulation. We did
> this, usually with a flush() then a clear() at appropriate milestones and it
> seemed to work just fine.
>
> However, since moving to 1.3.x (currently using 1.3.7) with the latest version
> of our product, the clear() method usage seems to have changed. As a result,
> while doing long lived transactions, when we issue a clear(), we immediately
> experience LazyInitializationException's and/or no Session for query etc. This
> is with code that has not changed since 1.0.6 usage.
>
> So has something changed in the underlying implementation, and should we not be
> using clear() anymore? I'm somewhat confused now. :-S Bert, are you out there?
> :-)
>
> Thanks,
> Darryl Pentz
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email