简体   繁体   中英

When does Grails close/flush Hibernate session?

I'm having an intermittent issue with Grails 2.2.2.

Controller 1: saves an object with GORM (eg, book.save() ) Controller 2: does a native query with Groovy.sql on the same table ( select * from BOOK... )

Both controllers are returning render ... as JSON , not using GSP.

The browser hits both controllers in immediate succession: the callback after controller 1 hits controller 2.

Normally this works fine, because I presume the underlying Hibernate session is flushed and closed after completing the request. But in rare instances, it seems like the rows haven't been inserted by the time the second controller fires. If I manually refresh the controller, though, the rows will have inserted properly - so the flush is happening, just a fraction of a second later than I expected it.

Is it possible that the browser could be treating the response as complete before the session is flushed?

See: http://jira.grails.org/browse/GRAILS-11049#comment-79366

It looks as if calling Grails is flushing the servlet output stream, so the Hibernate session hasn't been flushed until after the browser sees the complete response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM