Quantcast

How to prevent duplicate hibernate session

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to prevent duplicate hibernate session

benfreefly
Hi all,

I have a few pages in app that sometimes take a long time to load, due to background services blocking while reading from a huge XML feed and updating database data, etc.  Sometimes the users are impatient and hit refresh in the browser, resulting in an "org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions".

I'm working on a fix for the data processing so it doesn't block for so long, but in the meantime is there anything simple I can do to prevent the 2nd hibernate session from being created or kill the original one before starting the new request in this scenario?

I saw in another thread someone said to use .read() instead of .get(), but that's not an option for me as I am retrieving objects by criteria.

Any advice? Thanks in advance.
-Ben
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to prevent duplicate hibernate session

Jonathan Rosenberg
How about using withNewSession method?

       http://grails.org/doc/latest/ref/Domain%20Classes/withNewSession.html

--
Jonathan Rosenberg
Founder & Executive Director
Tabby's Place, a Cat Sanctuary
http://www.tabbysplace.org/


On Sat, Sep 24, 2011 at 1:45 PM, benfreefly <[hidden email]> wrote:
Hi all,

I have a few pages in app that sometimes take a long time to load, due to
background services blocking while reading from a huge XML feed and updating
database data, etc.  Sometimes the users are impatient and hit refresh in
the browser, resulting in an "org.hibernate.HibernateException: Illegal
attempt to associate a collection with two open sessions".

I'm working on a fix for the data processing so it doesn't block for so
long, but in the meantime is there anything simple I can do to prevent the
2nd hibernate session from being created or kill the original one before
starting the new request in this scenario?

I saw in another thread someone said to use .read() instead of .get(), but
that's not an option for me as I am retrieving objects by criteria.

Any advice? Thanks in advance.
-Ben

--
View this message in context: http://grails.1312388.n4.nabble.com/How-to-prevent-duplicate-hibernate-session-tp3839819p3839819.html
Sent from the Grails - user mailing list archive at Nabble.com.

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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to prevent duplicate hibernate session

benfreefly
Forgot about that one... thanks.  Just what I needed.
Loading...