Loading Hibernate DAO's in grails view and Lazy Initialization Errors
At the moment I'm on a project with grails and since I'm new to "grails & groovy" I discover problems everyday but most of the time it's not soooo hard to solve them because Grails / Rails / Symfony take the same aproche get thinks done. So in moste cases it's only a matter of minutes to get it right using google
This morning i discovered a real strange problem I had a navigation menue like this.
This morning i discovered a real strange problem I had a navigation menue like this.
- nav1
- nav2
- nav3
- sub1
- sub1
- sub1
-
- ${author.title}
-
But it failed, .... with Hibernate a Exception "... no session or session was closed ..." I had the exact same problem in the past in a normal spring project when you're hibernate session went away and you've tried to access the object that where connected to it ....
So spending quite some time in Google I discovered the solution in one of the Grails tutorials ... The solution was to add a Filter to the web.xml configuration to make database session available to Views AWWWSOME! Thanks buddies! Here is the code to add to you're web.xml
Next, locate the web.xml template, grails-app/src/templates/war/web.xml. Add the following:
hibernateFilter org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter hibernateFilter /*
Insert the above JUST BEFORE the firstin the template (it should be the charEncodingFilter).
Permalink Kommentare[1] Tags: initialization groovy hibernate web.xml filter errors no-session-or-session-was-closed closed grails loading session dao factory dataaccessobject views was java lazy









Alexander,
What version of grails were you using? I cannot get this to work with version 1.1.1 or 1.1.2. This would really save my day to see it work.
Gesendet von Ben am Dezember 09, 2009 at 05:54 PM MEZ #