ensuring hibernate session is bound to current thread

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

ensuring hibernate session is bound to current thread

Eamonn O'Connell-2
Hi all ,

I'm hoping someone can point me in the direction (so to speak) of how to ensure there is an active hibernate session attached to the thread. I'm aware of DomainClass.withNewSession { -> }

Is withNewSession always the way to go, or are there alternatives? It does not seem that the Executor plugin does not seem to use it for example.

Any tips very welome!

Thanks,
Eamonn
Reply | Threaded
Open this post in threaded view
|

Re: ensuring hibernate session is bound to current thread

basejump (Josh)
inject the persistenceInterceptor bean
persistenceInterceptor.init()
try {
//your code
} finally {
persistenceInterceptor.flush()
persistenceInterceptor.destroy()
}

see 
https://github.com/basejump/grails-executor/blob/master/src/groovy/grails/plugin/executor/PersistenceContextWrapper.groovy

On Nov 10, 2012, at 5:15 AM, Eamonn O'Connell wrote:

Hi all ,

I'm hoping someone can point me in the direction (so to speak) of how to ensure there is an active hibernate session attached to the thread. I'm aware of DomainClass.withNewSession { -> }

Is withNewSession always the way to go, or are there alternatives? It does not seem that the Executor plugin does not seem to use it for example.

Any tips very welome!

Thanks,
Eamonn

Reply | Threaded
Open this post in threaded view
|

Re: ensuring hibernate session is bound to current thread

Eamonn O'Connell-2
That was helpful. Thanks Josh!


On 10 November 2012 19:25, Josh (basejump) <[hidden email]> wrote:
inject the persistenceInterceptor bean
persistenceInterceptor.init()
try {
//your code
} finally {
persistenceInterceptor.flush()
persistenceInterceptor.destroy()
}

see 
https://github.com/basejump/grails-executor/blob/master/src/groovy/grails/plugin/executor/PersistenceContextWrapper.groovy


On Nov 10, 2012, at 5:15 AM, Eamonn O'Connell wrote:

Hi all ,

I'm hoping someone can point me in the direction (so to speak) of how to ensure there is an active hibernate session attached to the thread. I'm aware of DomainClass.withNewSession { -> }

Is withNewSession always the way to go, or are there alternatives? It does not seem that the Executor plugin does not seem to use it for example.

Any tips very welome!

Thanks,
Eamonn