Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - OSIV - Stop "Open Session In View" filter for Static Resources

Tags:

grails

I cross-posted in Javaranch too. I did my due diligence by doing Google search. I did not find any answer.

We have a REST service bases Web Application, for which backend is implemented using Groovy and Grails (1.3.7 with Groovy 1.7.x). I understand how Open Session In View works in general for Hibernate, and when configuring Hibernate with Spring, we could specify for which set of URLs, OSIV should work in the filter configuration.

The issue is I cannot find how to exclude a set of URLs from the scope of OSIV filter (like matching *.js, *.gif, etc). I found from the Hibernate log, that even for Javascript file request, Open Session In View kicks in and opens a session and closes it.

Thanks in advance.

like image 792
cspider Avatar asked Mar 13 '12 20:03

cspider


1 Answers

Grails has two implementations of the OSIV pattern, GrailsOpenSessionInViewFilter and GrailsOpenSessionInViewInterceptor. The filter was used in earlier versions of Grails but the interceptor is now what is used (at least in 1.2, 1.3 and 2.0). Since it's a WebRequestInterceptor it only applies to controller requests and not static requests for JavaScript, CSS, images, etc. So there's no performance concern for unnecessarily creating and binding a Hibernate session for simple file requests.

like image 147
Burt Beckwith Avatar answered Oct 06 '22 17:10

Burt Beckwith