Another Grails competitor

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

Another Grails competitor

Steven Devijver
I like their videos, I like their packaging and I'm in love with Vito.

http://blog.opensails.org/


Steven
Reply | Threaded
Open this post in threaded view
|

Re: Another Grails competitor

graemer
I watched the videos, havn't tried the actual app yet, but am I
missing something? He just created views and then loaded them in a
browser. I could have done that in HTML on any web server, what
exactly is so special? :-)

Maybe I need to take a look at the sample apps

Cheers
Graeme

On 04/02/06, Steven Devijver <[hidden email]> wrote:
> I like their videos, I like their packaging and I'm in love with Vito.
>
> http://blog.opensails.org/
>
>
> Steven
>
Reply | Threaded
Open this post in threaded view
|

RE: Another Grails competitor

Dierk König
In reply to this post by Steven Devijver
I'd say they compete with JSP, JSF, Tiles, Tapestry, WebWork,
and the like. Despite the name not with Grails, Rails, Trails, Jails, etc.
(just recognizing the 'Fails' is still untaken...)

I certainly support the idea of inventing new languages for
special tasks, but Viento doesn't appeal to me very much -
too perlish/PHP in design and not a 'real' language after all.

We can learn from the presentation:
- nice logo (see also http://groovy.canoo.com)
- coherent metaphor (although a bit annoying)
- pretty-printed code examples

cheers
Mittie


> -----Original Message-----
> From: Steven Devijver [mailto:[hidden email]]
> Sent: Sonntag, 5. Februar 2006 0:15
> To: [hidden email]
> Subject: [grails-user] Another Grails competitor
>
>
> I like their videos, I like their packaging and I'm in love with Vito.
>
> http://blog.opensails.org/
>
>
> Steven
Reply | Threaded
Open this post in threaded view
|

Re: Another Grails competitor

Steven Devijver
Yeah, sure, they don't provide persistence, it's more like a ready to
use MVC framework. Here are the things I like:

- logo and website
- opening the downloaded package in Eclipse and start a new project.
Includes HTTP server (Jetty). This would be an interesting option for
Grails.
- Viento - can't help it :-)



On 2/5/06, Dierk Koenig <[hidden email]> wrote:

> I'd say they compete with JSP, JSF, Tiles, Tapestry, WebWork,
> and the like. Despite the name not with Grails, Rails, Trails, Jails, etc.
> (just recognizing the 'Fails' is still untaken...)
>
> I certainly support the idea of inventing new languages for
> special tasks, but Viento doesn't appeal to me very much -
> too perlish/PHP in design and not a 'real' language after all.
>
> We can learn from the presentation:
> - nice logo (see also http://groovy.canoo.com)
> - coherent metaphor (although a bit annoying)
> - pretty-printed code examples
>
> cheers
> Mittie
>
>
> > -----Original Message-----
> > From: Steven Devijver [mailto:[hidden email]]
> > Sent: Sonntag, 5. Februar 2006 0:15
> > To: [hidden email]
> > Subject: [grails-user] Another Grails competitor
> >
> >
> > I like their videos, I like their packaging and I'm in love with Vito.
> >
> > http://blog.opensails.org/
> >
> >
> > Steven
>


--
Steven Devijver
Senior Consultant
Interface21
Spring Services from the Source
http://www.interface21.com

Co-author, "Expert Spring MVC and Web Flow"
(February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
http://www.amazon.com/gp/product/159059584X

Interface21 NL B.V.
Donker Curtiusstraat 7-400c
1051JL Amsterdam
The Netherlands
Phone: +31 (0)20 486 47 63
Fax: +31 (0)20 475 08 28
Mail: [hidden email]
Skype: devijvers
Reply | Threaded
Open this post in threaded view
|

RE: Another Grails competitor

Dierk König

> Includes HTTP server (Jetty). This would be an interesting option for
> Grails.

That's alredy included:
 grails run-app

:-)

cheers
Mittie
Reply | Threaded
Open this post in threaded view
|

Re: Another Grails competitor

graemer
I looked at viento.. can't say i'm overally impressed, i think there
could be much groovier options to shorten the tag syntax ;-)

The pre-packaged zip idea is a nice one... thats something we could do
with grails, but as dierk said we already package jetty so that areas
covered.

Graeme

On 05/02/06, Dierk Koenig <[hidden email]> wrote:

>
> > Includes HTTP server (Jetty). This would be an interesting option for
> > Grails.
>
> That's alredy included:
>  grails run-app
>
> :-)
>
> cheers
> Mittie
>
Reply | Threaded
Open this post in threaded view
|

Problems with getting relationsships out of database

Burkard Endres
hi,

i have a two classes

class Communication {
    @Property Long id;
    @Property Long version;
    @Property String type;
    @Property Boolean active;
    @Property String defUser;
    @Property Date   defTime;
    @Property String modUser;
    @Property Date modTime;
   
    @Property String content;
   
    @Property User user;
   
    @Property optionals = [ "modUser", "modTime"]
}

class User  {
    @Property Long id;
    @Property Long version;
    @Property String type;
    @Property Boolean active;
    @Property String defUser;
    @Property Date   defTime;
    @Property String modUser;
    @Property Date modTime;
   
    @Property String userName;
    @Property String password;
   
    @Property relationships = ["communications" : Communication.class];
    @Property optionals = [ "modUser", "modTime"];
   
    @Property Set communications = new HashSet();
   
    def void add(toAdd){
        toAdd.user = this
        toAdd.active = true
        toAdd.defTime = new Date()
        communications.add(toAdd)
    }
}

i have successfully inserted some datasets to the database (mysql)
when i call
user = User.findByUserNameAndPassword(<username>,<password>)
user.communications i get an Exception
   [script] failed to lazily initialize a collection of role:
User.communications - no session or session was closed
   [script] org.hibernate.LazyInitializationException: failed to lazily
initialize a collection of role: User.communications - no session or
session was closed
   [script]     at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
   [script]     at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
   [script]     at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
   [script]     at
org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
   [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)

can any of you tell me what i am doing wrong.
thanks

Burkard

Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

Steven Devijver
On 2/5/06, Burkard Endres <[hidden email]> wrote:

> hi,
>
> i have a two classes
>
> class Communication {
>     @Property Long id;
>     @Property Long version;
>     @Property String type;
>     @Property Boolean active;
>     @Property String defUser;
>     @Property Date   defTime;
>     @Property String modUser;
>     @Property Date modTime;
>
>     @Property String content;
>
>     @Property User user;
>
>     @Property optionals = [ "modUser", "modTime"]
> }
>
> class User  {
>     @Property Long id;
>     @Property Long version;
>     @Property String type;
>     @Property Boolean active;
>     @Property String defUser;
>     @Property Date   defTime;
>     @Property String modUser;
>     @Property Date modTime;
>
>     @Property String userName;
>     @Property String password;
>
>     @Property relationships = ["communications" : Communication.class];
>     @Property optionals = [ "modUser", "modTime"];
>
>     @Property Set communications = new HashSet();
>
>     def void add(toAdd){
>         toAdd.user = this
>         toAdd.active = true
>         toAdd.defTime = new Date()
>         communications.add(toAdd)
>     }
> }
>
> i have successfully inserted some datasets to the database (mysql)
> when i call
> user = User.findByUserNameAndPassword(<username>,<password>)
> user.communications i get an Exception
>    [script] failed to lazily initialize a collection of role:
> User.communications - no session or session was closed
>    [script] org.hibernate.LazyInitializationException: failed to lazily
> initialize a collection of role: User.communications - no session or
> session was closed
>    [script]     at
> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
>    [script]     at
> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
>    [script]     at
> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
>    [script]     at
> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>
> can any of you tell me what i am doing wrong.
> thanks
>
> Burkard
>
>

Hey Bukard,

This problem is caused because the Hibernate session is closed after
the persistence operation completes.

Guys, I think it makes sense to configure the OpenSessionInViewFilter
by default. As far as I understand, Hibernate 3.1 does not open a
connection to the database when the session is created, but at the
first occurence a connection is needed. Can anyone confirm this? This
should solve wasting valuable resources for every request.

Steven
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

Burkard Endres


Steven Devijver wrote:

> On 2/5/06, Burkard Endres <[hidden email]> wrote:
>  
>> hi,
>>
>> i have a two classes
>>
>> class Communication {
>>     @Property Long id;
>>     @Property Long version;
>>     @Property String type;
>>     @Property Boolean active;
>>     @Property String defUser;
>>     @Property Date   defTime;
>>     @Property String modUser;
>>     @Property Date modTime;
>>
>>     @Property String content;
>>
>>     @Property User user;
>>
>>     @Property optionals = [ "modUser", "modTime"]
>> }
>>
>> class User  {
>>     @Property Long id;
>>     @Property Long version;
>>     @Property String type;
>>     @Property Boolean active;
>>     @Property String defUser;
>>     @Property Date   defTime;
>>     @Property String modUser;
>>     @Property Date modTime;
>>
>>     @Property String userName;
>>     @Property String password;
>>
>>     @Property relationships = ["communications" : Communication.class];
>>     @Property optionals = [ "modUser", "modTime"];
>>
>>     @Property Set communications = new HashSet();
>>
>>     def void add(toAdd){
>>         toAdd.user = this
>>         toAdd.active = true
>>         toAdd.defTime = new Date()
>>         communications.add(toAdd)
>>     }
>> }
>>
>> i have successfully inserted some datasets to the database (mysql)
>> when i call
>> user = User.findByUserNameAndPassword(<username>,<password>)
>> user.communications i get an Exception
>>    [script] failed to lazily initialize a collection of role:
>> User.communications - no session or session was closed
>>    [script] org.hibernate.LazyInitializationException: failed to lazily
>> initialize a collection of role: User.communications - no session or
>> session was closed
>>    [script]     at
>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
>>    [script]     at
>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
>>    [script]     at
>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
>>    [script]     at
>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>> Method)
>>
>> can any of you tell me what i am doing wrong.
>> thanks
>>
>> Burkard
>>
>>
>>    
>
> Hey Bukard,
>
> This problem is caused because the Hibernate session is closed after
> the persistence operation completes.
>
> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> by default. As far as I understand, Hibernate 3.1 does not open a
> connection to the database when the session is created, but at the
> first occurence a connection is needed. Can anyone confirm this? This
> should solve wasting valuable resources for every request.
>
> Steven
>
>  

Hi Steven,

I thought there was OpenSessionInFilter configured, at least i get an
Exception where he occurs.

Burkard

   [script] failed to lazily initialize a collection of role:
User.communications - no session or session was closed
   [script] org.hibernate.LazyInitializationException: failed to lazily
initialize a collection of role: User.communications - no session or
session was closed
   [script]     at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
   [script]     at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
   [script]     at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
   [script]     at
org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
   [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
   [script]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   [script]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   [script]     at java.lang.reflect.Method.invoke(Method.java:585)
   [script]     at
org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
   [script]     at
org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
   [script]     at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
   [script]     at UserController.login(UserController:82)
   [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
Source)
   [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
   [script]     at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
   [script]     at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
   [script]     at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
   [script]     at
org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
   [script]     at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
   [script]     at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
   [script]     at UserController$_closure2.doCall(UserController:9)
   [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
   [script]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   [script]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   [script]     at java.lang.reflect.Method.invoke(Method.java:585)
   [script]     at
org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
   [script]     at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
   [script]     at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
   [script]     at
org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
   [script]     at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
   [script]     at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
   [script]     at UserController$_closure2.doCall(UserController)
   [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
   [script]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   [script]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   [script]     at java.lang.reflect.Method.invoke(Method.java:585)
   [script]     at
org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
   [script]     at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
   [script]     at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
   [script]     at groovy.lang.Closure.call(Closure.java:176)
   [script]     at groovy.lang.Closure.call(Closure.java:171)
   [script]     at
org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
   [script]     at
org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
   [script]     at
org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
   [script]     at
org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
   [script]     at
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   [script]     at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
   [script]     at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
   [script]     at
org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
   [script]     at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
   [script]     at
javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
   [script]     at
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   [script]     at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
   [script]     at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
   [script]     at
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
   [script]     at
org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
   [script]     at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   [script]     at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
   [script]     at
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
   [script]     at
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
   [script]     at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
   [script]     at
org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
   [script]     at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
   [script]     at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
   [script]     at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
   [script]     at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
   [script]     at
org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
   [script]     at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
   [script]     at
org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
   [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
   [script]     at
org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
   [script]     at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
   [script]     at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
   [script]     at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
   [script]     at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
   [script]     at
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)



Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

graemer
We already have an OpenSessionInViewFilter configured. See
http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java

which extends the Spring one to lookup the sessin factory from the
grails context

This seems to work when accessing relationships in the view but
Buckard is accessing it from the controller which is likely the
problem.. does the filter not cover this Steven? Or does it only open
the session once spring MVC forwards to the view?

Graeme



On 05/02/06, Burkard Endres <[hidden email]> wrote:

>
>
> Steven Devijver wrote:
> > On 2/5/06, Burkard Endres <[hidden email]> wrote:
> >
> >> hi,
> >>
> >> i have a two classes
> >>
> >> class Communication {
> >>     @Property Long id;
> >>     @Property Long version;
> >>     @Property String type;
> >>     @Property Boolean active;
> >>     @Property String defUser;
> >>     @Property Date   defTime;
> >>     @Property String modUser;
> >>     @Property Date modTime;
> >>
> >>     @Property String content;
> >>
> >>     @Property User user;
> >>
> >>     @Property optionals = [ "modUser", "modTime"]
> >> }
> >>
> >> class User  {
> >>     @Property Long id;
> >>     @Property Long version;
> >>     @Property String type;
> >>     @Property Boolean active;
> >>     @Property String defUser;
> >>     @Property Date   defTime;
> >>     @Property String modUser;
> >>     @Property Date modTime;
> >>
> >>     @Property String userName;
> >>     @Property String password;
> >>
> >>     @Property relationships = ["communications" : Communication.class];
> >>     @Property optionals = [ "modUser", "modTime"];
> >>
> >>     @Property Set communications = new HashSet();
> >>
> >>     def void add(toAdd){
> >>         toAdd.user = this
> >>         toAdd.active = true
> >>         toAdd.defTime = new Date()
> >>         communications.add(toAdd)
> >>     }
> >> }
> >>
> >> i have successfully inserted some datasets to the database (mysql)
> >> when i call
> >> user = User.findByUserNameAndPassword(<username>,<password>)
> >> user.communications i get an Exception
> >>    [script] failed to lazily initialize a collection of role:
> >> User.communications - no session or session was closed
> >>    [script] org.hibernate.LazyInitializationException: failed to lazily
> >> initialize a collection of role: User.communications - no session or
> >> session was closed
> >>    [script]     at
> >> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> >>    [script]     at
> >> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> >>    [script]     at
> >> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> >>    [script]     at
> >> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> >>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >> Method)
> >>
> >> can any of you tell me what i am doing wrong.
> >> thanks
> >>
> >> Burkard
> >>
> >>
> >>
> >
> > Hey Bukard,
> >
> > This problem is caused because the Hibernate session is closed after
> > the persistence operation completes.
> >
> > Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > by default. As far as I understand, Hibernate 3.1 does not open a
> > connection to the database when the session is created, but at the
> > first occurence a connection is needed. Can anyone confirm this? This
> > should solve wasting valuable resources for every request.
> >
> > Steven
> >
> >
>
> Hi Steven,
>
> I thought there was OpenSessionInFilter configured, at least i get an
> Exception where he occurs.
>
> Burkard
>
>    [script] failed to lazily initialize a collection of role:
> User.communications - no session or session was closed
>    [script] org.hibernate.LazyInitializationException: failed to lazily
> initialize a collection of role: User.communications - no session or
> session was closed
>    [script]     at
> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
>    [script]     at
> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
>    [script]     at
> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
>    [script]     at
> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>    [script]     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>    [script]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
>    [script]     at
> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
>    [script]     at
> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
>    [script]     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
>    [script]     at UserController.login(UserController:82)
>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> Source)
>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
>    [script]     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
>    [script]     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
>    [script]     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
>    [script]     at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>    [script]     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
>    [script]     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>    [script]     at UserController$_closure2.doCall(UserController:9)
>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>    [script]     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>    [script]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
>    [script]     at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
>    [script]     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
>    [script]     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
>    [script]     at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>    [script]     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
>    [script]     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>    [script]     at UserController$_closure2.doCall(UserController)
>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>    [script]     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>    [script]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
>    [script]     at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
>    [script]     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
>    [script]     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
>    [script]     at groovy.lang.Closure.call(Closure.java:176)
>    [script]     at groovy.lang.Closure.call(Closure.java:171)
>    [script]     at
> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
>    [script]     at
> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
>    [script]     at
> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
>    [script]     at
> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
>    [script]     at
> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
>    [script]     at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
>    [script]     at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
>    [script]     at
> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
>    [script]     at
> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
>    [script]     at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
>    [script]     at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>    [script]     at
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
>    [script]     at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
>    [script]     at
> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
>    [script]     at
> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
>    [script]     at
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>    [script]     at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
>    [script]     at
> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
>    [script]     at
> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
>    [script]     at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
>    [script]     at
> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
>    [script]     at
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>    [script]     at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
>    [script]     at
> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
>    [script]     at
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
>    [script]     at
> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
>    [script]     at
> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
>    [script]     at
> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
>    [script]     at
> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
>    [script]     at
> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
>    [script]     at
> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
>    [script]     at
> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
>    [script]     at
> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
>    [script]     at
> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

Steven Devijver
The filter gets invoked before the servlet is invoked, so everything
that happens inside Spring MVC and Grails should happen in the scope
of the filter, thus also the controller.

On 2/5/06, Graeme Rocher <[hidden email]> wrote:

> We already have an OpenSessionInViewFilter configured. See
> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
>
> which extends the Spring one to lookup the sessin factory from the
> grails context
>
> This seems to work when accessing relationships in the view but
> Buckard is accessing it from the controller which is likely the
> problem.. does the filter not cover this Steven? Or does it only open
> the session once spring MVC forwards to the view?
>
> Graeme
>
>
>
> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> >
> >
> > Steven Devijver wrote:
> > > On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > >
> > >> hi,
> > >>
> > >> i have a two classes
> > >>
> > >> class Communication {
> > >>     @Property Long id;
> > >>     @Property Long version;
> > >>     @Property String type;
> > >>     @Property Boolean active;
> > >>     @Property String defUser;
> > >>     @Property Date   defTime;
> > >>     @Property String modUser;
> > >>     @Property Date modTime;
> > >>
> > >>     @Property String content;
> > >>
> > >>     @Property User user;
> > >>
> > >>     @Property optionals = [ "modUser", "modTime"]
> > >> }
> > >>
> > >> class User  {
> > >>     @Property Long id;
> > >>     @Property Long version;
> > >>     @Property String type;
> > >>     @Property Boolean active;
> > >>     @Property String defUser;
> > >>     @Property Date   defTime;
> > >>     @Property String modUser;
> > >>     @Property Date modTime;
> > >>
> > >>     @Property String userName;
> > >>     @Property String password;
> > >>
> > >>     @Property relationships = ["communications" : Communication.class];
> > >>     @Property optionals = [ "modUser", "modTime"];
> > >>
> > >>     @Property Set communications = new HashSet();
> > >>
> > >>     def void add(toAdd){
> > >>         toAdd.user = this
> > >>         toAdd.active = true
> > >>         toAdd.defTime = new Date()
> > >>         communications.add(toAdd)
> > >>     }
> > >> }
> > >>
> > >> i have successfully inserted some datasets to the database (mysql)
> > >> when i call
> > >> user = User.findByUserNameAndPassword(<username>,<password>)
> > >> user.communications i get an Exception
> > >>    [script] failed to lazily initialize a collection of role:
> > >> User.communications - no session or session was closed
> > >>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > >> initialize a collection of role: User.communications - no session or
> > >> session was closed
> > >>    [script]     at
> > >> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > >>    [script]     at
> > >> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > >>    [script]     at
> > >> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > >>    [script]     at
> > >> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > >>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > >> Method)
> > >>
> > >> can any of you tell me what i am doing wrong.
> > >> thanks
> > >>
> > >> Burkard
> > >>
> > >>
> > >>
> > >
> > > Hey Bukard,
> > >
> > > This problem is caused because the Hibernate session is closed after
> > > the persistence operation completes.
> > >
> > > Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > > by default. As far as I understand, Hibernate 3.1 does not open a
> > > connection to the database when the session is created, but at the
> > > first occurence a connection is needed. Can anyone confirm this? This
> > > should solve wasting valuable resources for every request.
> > >
> > > Steven
> > >
> > >
> >
> > Hi Steven,
> >
> > I thought there was OpenSessionInFilter configured, at least i get an
> > Exception where he occurs.
> >
> > Burkard
> >
> >    [script] failed to lazily initialize a collection of role:
> > User.communications - no session or session was closed
> >    [script] org.hibernate.LazyInitializationException: failed to lazily
> > initialize a collection of role: User.communications - no session or
> > session was closed
> >    [script]     at
> > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> >    [script]     at
> > org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> >    [script]     at
> > org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> >    [script]     at
> > org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> >    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >    [script]     at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >    [script]     at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> >    [script]     at
> > org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> >    [script]     at
> > org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> >    [script]     at
> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> >    [script]     at UserController.login(UserController:82)
> >    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > Source)
> >    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> >    [script]     at
> > org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> >    [script]     at
> > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> >    [script]     at
> > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> >    [script]     at
> > org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> >    [script]     at
> > org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> >    [script]     at
> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> >    [script]     at UserController$_closure2.doCall(UserController:9)
> >    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >    [script]     at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >    [script]     at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> >    [script]     at
> > org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> >    [script]     at
> > org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> >    [script]     at
> > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> >    [script]     at
> > org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> >    [script]     at
> > org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> >    [script]     at
> > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> >    [script]     at UserController$_closure2.doCall(UserController)
> >    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >    [script]     at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >    [script]     at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> >    [script]     at
> > org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> >    [script]     at
> > org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> >    [script]     at
> > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> >    [script]     at groovy.lang.Closure.call(Closure.java:176)
> >    [script]     at groovy.lang.Closure.call(Closure.java:171)
> >    [script]     at
> > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> >    [script]     at
> > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> >    [script]     at
> > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> >    [script]     at
> > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> >    [script]     at
> > org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> >    [script]     at
> > org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> >    [script]     at
> > org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> >    [script]     at
> > org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> >    [script]     at
> > org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> >    [script]     at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> >    [script]     at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> >    [script]     at
> > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> >    [script]     at
> > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> >    [script]     at
> > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> >    [script]     at
> > org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> >    [script]     at
> > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> >    [script]     at
> > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> >    [script]     at
> > com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> >    [script]     at
> > com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> >    [script]     at
> > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> >    [script]     at
> > org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> >    [script]     at
> > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> >    [script]     at
> > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> >    [script]     at
> > org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> >    [script]     at
> > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> >    [script]     at
> > org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> >    [script]     at
> > org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> >    [script]     at
> > org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> >    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> >    [script]     at
> > org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> >    [script]     at
> > org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> >    [script]     at
> > org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> >    [script]     at
> > org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> >    [script]     at
> > org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> >    [script]     at
> > org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> >
> >
> >
> >
>


--
Steven Devijver
Senior Consultant
Interface21
Spring Services from the Source
http://www.interface21.com

Co-author, "Expert Spring MVC and Web Flow"
(February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
http://www.amazon.com/gp/product/159059584X

Interface21 NL B.V.
Donker Curtiusstraat 7-400c
1051JL Amsterdam
The Netherlands
Phone: +31 (0)20 486 47 63
Fax: +31 (0)20 475 08 28
Mail: [hidden email]
Skype: devijvers
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

graemer
Ok Thanks Steven,

Burkard where are you calling this method is it from a controller? I
have a feeling it might be from a bootstrap class in which case the
filter would never have been called and hence you would experience
this problem

Graeme

On 05/02/06, Steven Devijver <[hidden email]> wrote:

> The filter gets invoked before the servlet is invoked, so everything
> that happens inside Spring MVC and Grails should happen in the scope
> of the filter, thus also the controller.
>
> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> > We already have an OpenSessionInViewFilter configured. See
> > http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> >
> > which extends the Spring one to lookup the sessin factory from the
> > grails context
> >
> > This seems to work when accessing relationships in the view but
> > Buckard is accessing it from the controller which is likely the
> > problem.. does the filter not cover this Steven? Or does it only open
> > the session once spring MVC forwards to the view?
> >
> > Graeme
> >
> >
> >
> > On 05/02/06, Burkard Endres <[hidden email]> wrote:
> > >
> > >
> > > Steven Devijver wrote:
> > > > On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > > >
> > > >> hi,
> > > >>
> > > >> i have a two classes
> > > >>
> > > >> class Communication {
> > > >>     @Property Long id;
> > > >>     @Property Long version;
> > > >>     @Property String type;
> > > >>     @Property Boolean active;
> > > >>     @Property String defUser;
> > > >>     @Property Date   defTime;
> > > >>     @Property String modUser;
> > > >>     @Property Date modTime;
> > > >>
> > > >>     @Property String content;
> > > >>
> > > >>     @Property User user;
> > > >>
> > > >>     @Property optionals = [ "modUser", "modTime"]
> > > >> }
> > > >>
> > > >> class User  {
> > > >>     @Property Long id;
> > > >>     @Property Long version;
> > > >>     @Property String type;
> > > >>     @Property Boolean active;
> > > >>     @Property String defUser;
> > > >>     @Property Date   defTime;
> > > >>     @Property String modUser;
> > > >>     @Property Date modTime;
> > > >>
> > > >>     @Property String userName;
> > > >>     @Property String password;
> > > >>
> > > >>     @Property relationships = ["communications" : Communication.class];
> > > >>     @Property optionals = [ "modUser", "modTime"];
> > > >>
> > > >>     @Property Set communications = new HashSet();
> > > >>
> > > >>     def void add(toAdd){
> > > >>         toAdd.user = this
> > > >>         toAdd.active = true
> > > >>         toAdd.defTime = new Date()
> > > >>         communications.add(toAdd)
> > > >>     }
> > > >> }
> > > >>
> > > >> i have successfully inserted some datasets to the database (mysql)
> > > >> when i call
> > > >> user = User.findByUserNameAndPassword(<username>,<password>)
> > > >> user.communications i get an Exception
> > > >>    [script] failed to lazily initialize a collection of role:
> > > >> User.communications - no session or session was closed
> > > >>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > >> initialize a collection of role: User.communications - no session or
> > > >> session was closed
> > > >>    [script]     at
> > > >> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > >>    [script]     at
> > > >> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > >>    [script]     at
> > > >> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > >>    [script]     at
> > > >> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > >>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > >> Method)
> > > >>
> > > >> can any of you tell me what i am doing wrong.
> > > >> thanks
> > > >>
> > > >> Burkard
> > > >>
> > > >>
> > > >>
> > > >
> > > > Hey Bukard,
> > > >
> > > > This problem is caused because the Hibernate session is closed after
> > > > the persistence operation completes.
> > > >
> > > > Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > > > by default. As far as I understand, Hibernate 3.1 does not open a
> > > > connection to the database when the session is created, but at the
> > > > first occurence a connection is needed. Can anyone confirm this? This
> > > > should solve wasting valuable resources for every request.
> > > >
> > > > Steven
> > > >
> > > >
> > >
> > > Hi Steven,
> > >
> > > I thought there was OpenSessionInFilter configured, at least i get an
> > > Exception where he occurs.
> > >
> > > Burkard
> > >
> > >    [script] failed to lazily initialize a collection of role:
> > > User.communications - no session or session was closed
> > >    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > initialize a collection of role: User.communications - no session or
> > > session was closed
> > >    [script]     at
> > > org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > >    [script]     at
> > > org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > >    [script]     at
> > > org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > >    [script]     at
> > > org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > >    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > >    [script]     at
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >    [script]     at
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> > >    [script]     at UserController.login(UserController:82)
> > >    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > > Source)
> > >    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > >    [script]     at
> > > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > >    [script]     at
> > > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > >    [script]     at UserController$_closure2.doCall(UserController:9)
> > >    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > >    [script]     at
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >    [script]     at
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > >    [script]     at
> > > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > >    [script]     at UserController$_closure2.doCall(UserController)
> > >    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > Method)
> > >    [script]     at
> > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >    [script]     at
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > >    [script]     at
> > > org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > >    [script]     at
> > > groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > >    [script]     at groovy.lang.Closure.call(Closure.java:176)
> > >    [script]     at groovy.lang.Closure.call(Closure.java:171)
> > >    [script]     at
> > > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> > >    [script]     at
> > > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> > >    [script]     at
> > > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> > >    [script]     at
> > > org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> > >    [script]     at
> > > org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> > >    [script]     at
> > > org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> > >    [script]     at
> > > org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> > >    [script]     at
> > > org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> > >    [script]     at
> > > org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> > >    [script]     at
> > > javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> > >    [script]     at
> > > javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> > >    [script]     at
> > > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> > >    [script]     at
> > > org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> > >    [script]     at
> > > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > >    [script]     at
> > > com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> > >    [script]     at
> > > com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > >    [script]     at
> > > org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> > >    [script]     at
> > > org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> > >    [script]     at
> > > org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> > >    [script]     at
> > > org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> > >    [script]     at
> > > org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> > >    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> > >    [script]     at
> > > org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> > >    [script]     at
> > > org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> > >    [script]     at
> > > org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> > >    [script]     at
> > > org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> > >    [script]     at
> > > org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> > >    [script]     at
> > > org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> > >
> > >
> > >
> > >
> >
>
>
> --
> Steven Devijver
> Senior Consultant
> Interface21
> Spring Services from the Source
> http://www.interface21.com
>
> Co-author, "Expert Spring MVC and Web Flow"
> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> http://www.amazon.com/gp/product/159059584X
>
> Interface21 NL B.V.
> Donker Curtiusstraat 7-400c
> 1051JL Amsterdam
> The Netherlands
> Phone: +31 (0)20 486 47 63
> Fax: +31 (0)20 475 08 28
> Mail: [hidden email]
> Skype: devijvers
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

Burkard Endres
Hi Graeme,

i tried to call from a helper method within a controller.
This helper method was called by an action within the same controller.
And first i did a query to database with
session.user = User.findByUserNameAndPassword(....
and then i did a System.out in the helpermethod to session.user.userName
and it printed out the correct name.
and then i called in the same method session.user.communications and
then i get the error.

Burkard


Graeme Rocher wrote:

> Ok Thanks Steven,
>
> Burkard where are you calling this method is it from a controller? I
> have a feeling it might be from a bootstrap class in which case the
> filter would never have been called and hence you would experience
> this problem
>
> Graeme
>
> On 05/02/06, Steven Devijver <[hidden email]> wrote:
>  
>> The filter gets invoked before the servlet is invoked, so everything
>> that happens inside Spring MVC and Grails should happen in the scope
>> of the filter, thus also the controller.
>>
>> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
>>    
>>> We already have an OpenSessionInViewFilter configured. See
>>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
>>>
>>> which extends the Spring one to lookup the sessin factory from the
>>> grails context
>>>
>>> This seems to work when accessing relationships in the view but
>>> Buckard is accessing it from the controller which is likely the
>>> problem.. does the filter not cover this Steven? Or does it only open
>>> the session once spring MVC forwards to the view?
>>>
>>> Graeme
>>>
>>>
>>>
>>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
>>>      
>>>> Steven Devijver wrote:
>>>>        
>>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
>>>>>
>>>>>          
>>>>>> hi,
>>>>>>
>>>>>> i have a two classes
>>>>>>
>>>>>> class Communication {
>>>>>>     @Property Long id;
>>>>>>     @Property Long version;
>>>>>>     @Property String type;
>>>>>>     @Property Boolean active;
>>>>>>     @Property String defUser;
>>>>>>     @Property Date   defTime;
>>>>>>     @Property String modUser;
>>>>>>     @Property Date modTime;
>>>>>>
>>>>>>     @Property String content;
>>>>>>
>>>>>>     @Property User user;
>>>>>>
>>>>>>     @Property optionals = [ "modUser", "modTime"]
>>>>>> }
>>>>>>
>>>>>> class User  {
>>>>>>     @Property Long id;
>>>>>>     @Property Long version;
>>>>>>     @Property String type;
>>>>>>     @Property Boolean active;
>>>>>>     @Property String defUser;
>>>>>>     @Property Date   defTime;
>>>>>>     @Property String modUser;
>>>>>>     @Property Date modTime;
>>>>>>
>>>>>>     @Property String userName;
>>>>>>     @Property String password;
>>>>>>
>>>>>>     @Property relationships = ["communications" : Communication.class];
>>>>>>     @Property optionals = [ "modUser", "modTime"];
>>>>>>
>>>>>>     @Property Set communications = new HashSet();
>>>>>>
>>>>>>     def void add(toAdd){
>>>>>>         toAdd.user = this
>>>>>>         toAdd.active = true
>>>>>>         toAdd.defTime = new Date()
>>>>>>         communications.add(toAdd)
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> i have successfully inserted some datasets to the database (mysql)
>>>>>> when i call
>>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
>>>>>> user.communications i get an Exception
>>>>>>    [script] failed to lazily initialize a collection of role:
>>>>>> User.communications - no session or session was closed
>>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
>>>>>> initialize a collection of role: User.communications - no session or
>>>>>> session was closed
>>>>>>    [script]     at
>>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
>>>>>>    [script]     at
>>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
>>>>>>    [script]     at
>>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
>>>>>>    [script]     at
>>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
>>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>>>> Method)
>>>>>>
>>>>>> can any of you tell me what i am doing wrong.
>>>>>> thanks
>>>>>>
>>>>>> Burkard
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>> Hey Bukard,
>>>>>
>>>>> This problem is caused because the Hibernate session is closed after
>>>>> the persistence operation completes.
>>>>>
>>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
>>>>> by default. As far as I understand, Hibernate 3.1 does not open a
>>>>> connection to the database when the session is created, but at the
>>>>> first occurence a connection is needed. Can anyone confirm this? This
>>>>> should solve wasting valuable resources for every request.
>>>>>
>>>>> Steven
>>>>>
>>>>>
>>>>>          
>>>> Hi Steven,
>>>>
>>>> I thought there was OpenSessionInFilter configured, at least i get an
>>>> Exception where he occurs.
>>>>
>>>> Burkard
>>>>
>>>>    [script] failed to lazily initialize a collection of role:
>>>> User.communications - no session or session was closed
>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
>>>> initialize a collection of role: User.communications - no session or
>>>> session was closed
>>>>    [script]     at
>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
>>>>    [script]     at
>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
>>>>    [script]     at
>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
>>>>    [script]     at
>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>> Method)
>>>>    [script]     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>    [script]     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
>>>>    [script]     at UserController.login(UserController:82)
>>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
>>>> Source)
>>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
>>>>    [script]     at
>>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
>>>>    [script]     at
>>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>>>>    [script]     at UserController$_closure2.doCall(UserController:9)
>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>> Method)
>>>>    [script]     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>    [script]     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
>>>>    [script]     at
>>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>>>>    [script]     at UserController$_closure2.doCall(UserController)
>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>> Method)
>>>>    [script]     at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>    [script]     at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
>>>>    [script]     at
>>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
>>>>    [script]     at
>>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
>>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
>>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
>>>>    [script]     at
>>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
>>>>    [script]     at
>>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
>>>>    [script]     at
>>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
>>>>    [script]     at
>>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
>>>>    [script]     at
>>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
>>>>    [script]     at
>>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
>>>>    [script]     at
>>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
>>>>    [script]     at
>>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
>>>>    [script]     at
>>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
>>>>    [script]     at
>>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
>>>>    [script]     at
>>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
>>>>    [script]     at
>>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
>>>>    [script]     at
>>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
>>>>    [script]     at
>>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
>>>>    [script]     at
>>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
>>>>    [script]     at
>>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
>>>>    [script]     at
>>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
>>>>    [script]     at
>>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
>>>>    [script]     at
>>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
>>>>    [script]     at
>>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
>>>>    [script]     at
>>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
>>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
>>>>    [script]     at
>>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
>>>>    [script]     at
>>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
>>>>    [script]     at
>>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
>>>>    [script]     at
>>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
>>>>    [script]     at
>>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
>>>>    [script]     at
>>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
>>>>
>>>>
>>>>
>>>>
>>>>        
>> --
>> Steven Devijver
>> Senior Consultant
>> Interface21
>> Spring Services from the Source
>> http://www.interface21.com
>>
>> Co-author, "Expert Spring MVC and Web Flow"
>> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
>> http://www.amazon.com/gp/product/159059584X
>>
>> Interface21 NL B.V.
>> Donker Curtiusstraat 7-400c
>> 1051JL Amsterdam
>> The Netherlands
>> Phone: +31 (0)20 486 47 63
>> Fax: +31 (0)20 475 08 28
>> Mail: [hidden email]
>> Skype: devijvers
>>
>>    
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

graemer
Thanks Burkard.

Steven I have run the code through a debugger and it seems to be a
problem with the way the SessionFactory is bound the the
TransactionSynchronizationManager. When it is actually bound by the
OpenSessionViewInFilter it uses a map with the sessionfactory as the
key. At the point of binding it is wrapped in a proxy:

{$Proxy0@4420}org.hibernate.impl.SessionFactoryImpl@1d0eb0b

Later when it is retrieved by the HibernateTemplate it uses the
SessionFactory as the key again, but it doesn't appear wrapped in a
Proxy:

org.hibernate.impl.SessionFactoryImpl@1d0eb0b

As the sessionFactory is the key it and it is dfiferent when wrapped
and not wrapped in the proxy i thinks there is no session bound to the
current thread and closes the session resulting in subsequent calls
having a closed session bound to the thread

Do you know why this could be happening? I will keep digging..

Cheers
Graeme

On 06/02/06, Burkard Endres <[hidden email]> wrote:

> Hi Graeme,
>
> i tried to call from a helper method within a controller.
> This helper method was called by an action within the same controller.
> And first i did a query to database with
> session.user = User.findByUserNameAndPassword(....
> and then i did a System.out in the helpermethod to session.user.userName
> and it printed out the correct name.
> and then i called in the same method session.user.communications and
> then i get the error.
>
> Burkard
>
>
> Graeme Rocher wrote:
> > Ok Thanks Steven,
> >
> > Burkard where are you calling this method is it from a controller? I
> > have a feeling it might be from a bootstrap class in which case the
> > filter would never have been called and hence you would experience
> > this problem
> >
> > Graeme
> >
> > On 05/02/06, Steven Devijver <[hidden email]> wrote:
> >
> >> The filter gets invoked before the servlet is invoked, so everything
> >> that happens inside Spring MVC and Grails should happen in the scope
> >> of the filter, thus also the controller.
> >>
> >> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> >>
> >>> We already have an OpenSessionInViewFilter configured. See
> >>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> >>>
> >>> which extends the Spring one to lookup the sessin factory from the
> >>> grails context
> >>>
> >>> This seems to work when accessing relationships in the view but
> >>> Buckard is accessing it from the controller which is likely the
> >>> problem.. does the filter not cover this Steven? Or does it only open
> >>> the session once spring MVC forwards to the view?
> >>>
> >>> Graeme
> >>>
> >>>
> >>>
> >>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> >>>
> >>>> Steven Devijver wrote:
> >>>>
> >>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
> >>>>>
> >>>>>
> >>>>>> hi,
> >>>>>>
> >>>>>> i have a two classes
> >>>>>>
> >>>>>> class Communication {
> >>>>>>     @Property Long id;
> >>>>>>     @Property Long version;
> >>>>>>     @Property String type;
> >>>>>>     @Property Boolean active;
> >>>>>>     @Property String defUser;
> >>>>>>     @Property Date   defTime;
> >>>>>>     @Property String modUser;
> >>>>>>     @Property Date modTime;
> >>>>>>
> >>>>>>     @Property String content;
> >>>>>>
> >>>>>>     @Property User user;
> >>>>>>
> >>>>>>     @Property optionals = [ "modUser", "modTime"]
> >>>>>> }
> >>>>>>
> >>>>>> class User  {
> >>>>>>     @Property Long id;
> >>>>>>     @Property Long version;
> >>>>>>     @Property String type;
> >>>>>>     @Property Boolean active;
> >>>>>>     @Property String defUser;
> >>>>>>     @Property Date   defTime;
> >>>>>>     @Property String modUser;
> >>>>>>     @Property Date modTime;
> >>>>>>
> >>>>>>     @Property String userName;
> >>>>>>     @Property String password;
> >>>>>>
> >>>>>>     @Property relationships = ["communications" : Communication.class];
> >>>>>>     @Property optionals = [ "modUser", "modTime"];
> >>>>>>
> >>>>>>     @Property Set communications = new HashSet();
> >>>>>>
> >>>>>>     def void add(toAdd){
> >>>>>>         toAdd.user = this
> >>>>>>         toAdd.active = true
> >>>>>>         toAdd.defTime = new Date()
> >>>>>>         communications.add(toAdd)
> >>>>>>     }
> >>>>>> }
> >>>>>>
> >>>>>> i have successfully inserted some datasets to the database (mysql)
> >>>>>> when i call
> >>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
> >>>>>> user.communications i get an Exception
> >>>>>>    [script] failed to lazily initialize a collection of role:
> >>>>>> User.communications - no session or session was closed
> >>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> >>>>>> initialize a collection of role: User.communications - no session or
> >>>>>> session was closed
> >>>>>>    [script]     at
> >>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> >>>>>>    [script]     at
> >>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> >>>>>>    [script]     at
> >>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> >>>>>>    [script]     at
> >>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> >>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>>>>> Method)
> >>>>>>
> >>>>>> can any of you tell me what i am doing wrong.
> >>>>>> thanks
> >>>>>>
> >>>>>> Burkard
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>> Hey Bukard,
> >>>>>
> >>>>> This problem is caused because the Hibernate session is closed after
> >>>>> the persistence operation completes.
> >>>>>
> >>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> >>>>> by default. As far as I understand, Hibernate 3.1 does not open a
> >>>>> connection to the database when the session is created, but at the
> >>>>> first occurence a connection is needed. Can anyone confirm this? This
> >>>>> should solve wasting valuable resources for every request.
> >>>>>
> >>>>> Steven
> >>>>>
> >>>>>
> >>>>>
> >>>> Hi Steven,
> >>>>
> >>>> I thought there was OpenSessionInFilter configured, at least i get an
> >>>> Exception where he occurs.
> >>>>
> >>>> Burkard
> >>>>
> >>>>    [script] failed to lazily initialize a collection of role:
> >>>> User.communications - no session or session was closed
> >>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> >>>> initialize a collection of role: User.communications - no session or
> >>>> session was closed
> >>>>    [script]     at
> >>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> >>>>    [script]     at
> >>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> >>>>    [script]     at
> >>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> >>>>    [script]     at
> >>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>>> Method)
> >>>>    [script]     at
> >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >>>>    [script]     at
> >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> >>>>    [script]     at UserController.login(UserController:82)
> >>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> >>>> Source)
> >>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> >>>>    [script]     at
> >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> >>>>    [script]     at
> >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> >>>>    [script]     at UserController$_closure2.doCall(UserController:9)
> >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>>> Method)
> >>>>    [script]     at
> >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >>>>    [script]     at
> >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> >>>>    [script]     at
> >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> >>>>    [script]     at UserController$_closure2.doCall(UserController)
> >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>>> Method)
> >>>>    [script]     at
> >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >>>>    [script]     at
> >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> >>>>    [script]     at
> >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> >>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
> >>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> >>>>    [script]     at
> >>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> >>>>    [script]     at
> >>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> >>>>    [script]     at
> >>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> >>>>    [script]     at
> >>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> >>>>    [script]     at
> >>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> >>>>    [script]     at
> >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> >>>>    [script]     at
> >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> >>>>    [script]     at
> >>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> >>>>    [script]     at
> >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> >>>>    [script]     at
> >>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> >>>>    [script]     at
> >>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> >>>>    [script]     at
> >>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> >>>>    [script]     at
> >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> >>>>    [script]     at
> >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> >>>>    [script]     at
> >>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> >>>>    [script]     at
> >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> >>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> >>>>    [script]     at
> >>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> >>>>    [script]     at
> >>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> >>>>    [script]     at
> >>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> >>>>    [script]     at
> >>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> >>>>    [script]     at
> >>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> >>>>    [script]     at
> >>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >> --
> >> Steven Devijver
> >> Senior Consultant
> >> Interface21
> >> Spring Services from the Source
> >> http://www.interface21.com
> >>
> >> Co-author, "Expert Spring MVC and Web Flow"
> >> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> >> http://www.amazon.com/gp/product/159059584X
> >>
> >> Interface21 NL B.V.
> >> Donker Curtiusstraat 7-400c
> >> 1051JL Amsterdam
> >> The Netherlands
> >> Phone: +31 (0)20 486 47 63
> >> Fax: +31 (0)20 475 08 28
> >> Mail: [hidden email]
> >> Skype: devijvers
> >>
> >>
> >
> >
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

Steven Devijver
Wrapped in a proxy??!

This is the strangest story I've heard all morning.

Can you check if it's a Spring AOP proxy? You can cast it to the
Advised interface as a test or use AopUtils.isAopProxy().

Steven

On 2/6/06, Graeme Rocher <[hidden email]> wrote:

> Thanks Burkard.
>
> Steven I have run the code through a debugger and it seems to be a
> problem with the way the SessionFactory is bound the the
> TransactionSynchronizationManager. When it is actually bound by the
> OpenSessionViewInFilter it uses a map with the sessionfactory as the
> key. At the point of binding it is wrapped in a proxy:
>
> {$Proxy0@4420}org.hibernate.impl.SessionFactoryImpl@1d0eb0b
>
> Later when it is retrieved by the HibernateTemplate it uses the
> SessionFactory as the key again, but it doesn't appear wrapped in a
> Proxy:
>
> org.hibernate.impl.SessionFactoryImpl@1d0eb0b
>
> As the sessionFactory is the key it and it is dfiferent when wrapped
> and not wrapped in the proxy i thinks there is no session bound to the
> current thread and closes the session resulting in subsequent calls
> having a closed session bound to the thread
>
> Do you know why this could be happening? I will keep digging..
>
> Cheers
> Graeme
>
> On 06/02/06, Burkard Endres <[hidden email]> wrote:
> > Hi Graeme,
> >
> > i tried to call from a helper method within a controller.
> > This helper method was called by an action within the same controller.
> > And first i did a query to database with
> > session.user = User.findByUserNameAndPassword(....
> > and then i did a System.out in the helpermethod to session.user.userName
> > and it printed out the correct name.
> > and then i called in the same method session.user.communications and
> > then i get the error.
> >
> > Burkard
> >
> >
> > Graeme Rocher wrote:
> > > Ok Thanks Steven,
> > >
> > > Burkard where are you calling this method is it from a controller? I
> > > have a feeling it might be from a bootstrap class in which case the
> > > filter would never have been called and hence you would experience
> > > this problem
> > >
> > > Graeme
> > >
> > > On 05/02/06, Steven Devijver <[hidden email]> wrote:
> > >
> > >> The filter gets invoked before the servlet is invoked, so everything
> > >> that happens inside Spring MVC and Grails should happen in the scope
> > >> of the filter, thus also the controller.
> > >>
> > >> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> > >>
> > >>> We already have an OpenSessionInViewFilter configured. See
> > >>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> > >>>
> > >>> which extends the Spring one to lookup the sessin factory from the
> > >>> grails context
> > >>>
> > >>> This seems to work when accessing relationships in the view but
> > >>> Buckard is accessing it from the controller which is likely the
> > >>> problem.. does the filter not cover this Steven? Or does it only open
> > >>> the session once spring MVC forwards to the view?
> > >>>
> > >>> Graeme
> > >>>
> > >>>
> > >>>
> > >>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> > >>>
> > >>>> Steven Devijver wrote:
> > >>>>
> > >>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > >>>>>
> > >>>>>
> > >>>>>> hi,
> > >>>>>>
> > >>>>>> i have a two classes
> > >>>>>>
> > >>>>>> class Communication {
> > >>>>>>     @Property Long id;
> > >>>>>>     @Property Long version;
> > >>>>>>     @Property String type;
> > >>>>>>     @Property Boolean active;
> > >>>>>>     @Property String defUser;
> > >>>>>>     @Property Date   defTime;
> > >>>>>>     @Property String modUser;
> > >>>>>>     @Property Date modTime;
> > >>>>>>
> > >>>>>>     @Property String content;
> > >>>>>>
> > >>>>>>     @Property User user;
> > >>>>>>
> > >>>>>>     @Property optionals = [ "modUser", "modTime"]
> > >>>>>> }
> > >>>>>>
> > >>>>>> class User  {
> > >>>>>>     @Property Long id;
> > >>>>>>     @Property Long version;
> > >>>>>>     @Property String type;
> > >>>>>>     @Property Boolean active;
> > >>>>>>     @Property String defUser;
> > >>>>>>     @Property Date   defTime;
> > >>>>>>     @Property String modUser;
> > >>>>>>     @Property Date modTime;
> > >>>>>>
> > >>>>>>     @Property String userName;
> > >>>>>>     @Property String password;
> > >>>>>>
> > >>>>>>     @Property relationships = ["communications" : Communication.class];
> > >>>>>>     @Property optionals = [ "modUser", "modTime"];
> > >>>>>>
> > >>>>>>     @Property Set communications = new HashSet();
> > >>>>>>
> > >>>>>>     def void add(toAdd){
> > >>>>>>         toAdd.user = this
> > >>>>>>         toAdd.active = true
> > >>>>>>         toAdd.defTime = new Date()
> > >>>>>>         communications.add(toAdd)
> > >>>>>>     }
> > >>>>>> }
> > >>>>>>
> > >>>>>> i have successfully inserted some datasets to the database (mysql)
> > >>>>>> when i call
> > >>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
> > >>>>>> user.communications i get an Exception
> > >>>>>>    [script] failed to lazily initialize a collection of role:
> > >>>>>> User.communications - no session or session was closed
> > >>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > >>>>>> initialize a collection of role: User.communications - no session or
> > >>>>>> session was closed
> > >>>>>>    [script]     at
> > >>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > >>>>>>    [script]     at
> > >>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > >>>>>>    [script]     at
> > >>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > >>>>>>    [script]     at
> > >>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > >>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > >>>>>> Method)
> > >>>>>>
> > >>>>>> can any of you tell me what i am doing wrong.
> > >>>>>> thanks
> > >>>>>>
> > >>>>>> Burkard
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>> Hey Bukard,
> > >>>>>
> > >>>>> This problem is caused because the Hibernate session is closed after
> > >>>>> the persistence operation completes.
> > >>>>>
> > >>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > >>>>> by default. As far as I understand, Hibernate 3.1 does not open a
> > >>>>> connection to the database when the session is created, but at the
> > >>>>> first occurence a connection is needed. Can anyone confirm this? This
> > >>>>> should solve wasting valuable resources for every request.
> > >>>>>
> > >>>>> Steven
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>> Hi Steven,
> > >>>>
> > >>>> I thought there was OpenSessionInFilter configured, at least i get an
> > >>>> Exception where he occurs.
> > >>>>
> > >>>> Burkard
> > >>>>
> > >>>>    [script] failed to lazily initialize a collection of role:
> > >>>> User.communications - no session or session was closed
> > >>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > >>>> initialize a collection of role: User.communications - no session or
> > >>>> session was closed
> > >>>>    [script]     at
> > >>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > >>>>    [script]     at
> > >>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > >>>>    [script]     at
> > >>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > >>>>    [script]     at
> > >>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > >>>> Method)
> > >>>>    [script]     at
> > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >>>>    [script]     at
> > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> > >>>>    [script]     at UserController.login(UserController:82)
> > >>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > >>>> Source)
> > >>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > >>>>    [script]     at
> > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > >>>>    [script]     at
> > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > >>>>    [script]     at UserController$_closure2.doCall(UserController:9)
> > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > >>>> Method)
> > >>>>    [script]     at
> > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >>>>    [script]     at
> > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > >>>>    [script]     at
> > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > >>>>    [script]     at UserController$_closure2.doCall(UserController)
> > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > >>>> Method)
> > >>>>    [script]     at
> > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >>>>    [script]     at
> > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > >>>>    [script]     at
> > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
> > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> > >>>>    [script]     at
> > >>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> > >>>>    [script]     at
> > >>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> > >>>>    [script]     at
> > >>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> > >>>>    [script]     at
> > >>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> > >>>>    [script]     at
> > >>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> > >>>>    [script]     at
> > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> > >>>>    [script]     at
> > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> > >>>>    [script]     at
> > >>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> > >>>>    [script]     at
> > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > >>>>    [script]     at
> > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> > >>>>    [script]     at
> > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > >>>>    [script]     at
> > >>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> > >>>>    [script]     at
> > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> > >>>>    [script]     at
> > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> > >>>>    [script]     at
> > >>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> > >>>>    [script]     at
> > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> > >>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> > >>>>    [script]     at
> > >>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> > >>>>    [script]     at
> > >>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> > >>>>    [script]     at
> > >>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> > >>>>    [script]     at
> > >>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> > >>>>    [script]     at
> > >>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> > >>>>    [script]     at
> > >>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >> --
> > >> Steven Devijver
> > >> Senior Consultant
> > >> Interface21
> > >> Spring Services from the Source
> > >> http://www.interface21.com
> > >>
> > >> Co-author, "Expert Spring MVC and Web Flow"
> > >> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > >> http://www.amazon.com/gp/product/159059584X
> > >>
> > >> Interface21 NL B.V.
> > >> Donker Curtiusstraat 7-400c
> > >> 1051JL Amsterdam
> > >> The Netherlands
> > >> Phone: +31 (0)20 486 47 63
> > >> Fax: +31 (0)20 475 08 28
> > >> Mail: [hidden email]
> > >> Skype: devijvers
> > >>
> > >>
> > >
> > >
> >
> >
>


--
Steven Devijver
Senior Consultant
Interface21
Spring Services from the Source
http://www.interface21.com

Co-author, "Expert Spring MVC and Web Flow"
(February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
http://www.amazon.com/gp/product/159059584X

Interface21 NL B.V.
Donker Curtiusstraat 7-400c
1051JL Amsterdam
The Netherlands
Phone: +31 (0)20 486 47 63
Fax: +31 (0)20 475 08 28
Mail: [hidden email]
Skype: devijvers
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

graemer
On 06/02/06, Steven Devijver <[hidden email]> wrote:
> Wrapped in a proxy??!
>
> This is the strangest story I've heard all morning.
>
> Can you check if it's a Spring AOP proxy? You can cast it to the
> Advised interface as a test or use AopUtils.isAopProxy().

Ok will try

Graeme

>
> Steven
>
> On 2/6/06, Graeme Rocher <[hidden email]> wrote:
> > Thanks Burkard.
> >
> > Steven I have run the code through a debugger and it seems to be a
> > problem with the way the SessionFactory is bound the the
> > TransactionSynchronizationManager. When it is actually bound by the
> > OpenSessionViewInFilter it uses a map with the sessionfactory as the
> > key. At the point of binding it is wrapped in a proxy:
> >
> > {$Proxy0@4420}org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> >
> > Later when it is retrieved by the HibernateTemplate it uses the
> > SessionFactory as the key again, but it doesn't appear wrapped in a
> > Proxy:
> >
> > org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> >
> > As the sessionFactory is the key it and it is dfiferent when wrapped
> > and not wrapped in the proxy i thinks there is no session bound to the
> > current thread and closes the session resulting in subsequent calls
> > having a closed session bound to the thread
> >
> > Do you know why this could be happening? I will keep digging..
> >
> > Cheers
> > Graeme
> >
> > On 06/02/06, Burkard Endres <[hidden email]> wrote:
> > > Hi Graeme,
> > >
> > > i tried to call from a helper method within a controller.
> > > This helper method was called by an action within the same controller.
> > > And first i did a query to database with
> > > session.user = User.findByUserNameAndPassword(....
> > > and then i did a System.out in the helpermethod to session.user.userName
> > > and it printed out the correct name.
> > > and then i called in the same method session.user.communications and
> > > then i get the error.
> > >
> > > Burkard
> > >
> > >
> > > Graeme Rocher wrote:
> > > > Ok Thanks Steven,
> > > >
> > > > Burkard where are you calling this method is it from a controller? I
> > > > have a feeling it might be from a bootstrap class in which case the
> > > > filter would never have been called and hence you would experience
> > > > this problem
> > > >
> > > > Graeme
> > > >
> > > > On 05/02/06, Steven Devijver <[hidden email]> wrote:
> > > >
> > > >> The filter gets invoked before the servlet is invoked, so everything
> > > >> that happens inside Spring MVC and Grails should happen in the scope
> > > >> of the filter, thus also the controller.
> > > >>
> > > >> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> > > >>
> > > >>> We already have an OpenSessionInViewFilter configured. See
> > > >>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> > > >>>
> > > >>> which extends the Spring one to lookup the sessin factory from the
> > > >>> grails context
> > > >>>
> > > >>> This seems to work when accessing relationships in the view but
> > > >>> Buckard is accessing it from the controller which is likely the
> > > >>> problem.. does the filter not cover this Steven? Or does it only open
> > > >>> the session once spring MVC forwards to the view?
> > > >>>
> > > >>> Graeme
> > > >>>
> > > >>>
> > > >>>
> > > >>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> > > >>>
> > > >>>> Steven Devijver wrote:
> > > >>>>
> > > >>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > > >>>>>
> > > >>>>>
> > > >>>>>> hi,
> > > >>>>>>
> > > >>>>>> i have a two classes
> > > >>>>>>
> > > >>>>>> class Communication {
> > > >>>>>>     @Property Long id;
> > > >>>>>>     @Property Long version;
> > > >>>>>>     @Property String type;
> > > >>>>>>     @Property Boolean active;
> > > >>>>>>     @Property String defUser;
> > > >>>>>>     @Property Date   defTime;
> > > >>>>>>     @Property String modUser;
> > > >>>>>>     @Property Date modTime;
> > > >>>>>>
> > > >>>>>>     @Property String content;
> > > >>>>>>
> > > >>>>>>     @Property User user;
> > > >>>>>>
> > > >>>>>>     @Property optionals = [ "modUser", "modTime"]
> > > >>>>>> }
> > > >>>>>>
> > > >>>>>> class User  {
> > > >>>>>>     @Property Long id;
> > > >>>>>>     @Property Long version;
> > > >>>>>>     @Property String type;
> > > >>>>>>     @Property Boolean active;
> > > >>>>>>     @Property String defUser;
> > > >>>>>>     @Property Date   defTime;
> > > >>>>>>     @Property String modUser;
> > > >>>>>>     @Property Date modTime;
> > > >>>>>>
> > > >>>>>>     @Property String userName;
> > > >>>>>>     @Property String password;
> > > >>>>>>
> > > >>>>>>     @Property relationships = ["communications" : Communication.class];
> > > >>>>>>     @Property optionals = [ "modUser", "modTime"];
> > > >>>>>>
> > > >>>>>>     @Property Set communications = new HashSet();
> > > >>>>>>
> > > >>>>>>     def void add(toAdd){
> > > >>>>>>         toAdd.user = this
> > > >>>>>>         toAdd.active = true
> > > >>>>>>         toAdd.defTime = new Date()
> > > >>>>>>         communications.add(toAdd)
> > > >>>>>>     }
> > > >>>>>> }
> > > >>>>>>
> > > >>>>>> i have successfully inserted some datasets to the database (mysql)
> > > >>>>>> when i call
> > > >>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
> > > >>>>>> user.communications i get an Exception
> > > >>>>>>    [script] failed to lazily initialize a collection of role:
> > > >>>>>> User.communications - no session or session was closed
> > > >>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > >>>>>> initialize a collection of role: User.communications - no session or
> > > >>>>>> session was closed
> > > >>>>>>    [script]     at
> > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > >>>>>>    [script]     at
> > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > >>>>>>    [script]     at
> > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > >>>>>>    [script]     at
> > > >>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > >>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > >>>>>> Method)
> > > >>>>>>
> > > >>>>>> can any of you tell me what i am doing wrong.
> > > >>>>>> thanks
> > > >>>>>>
> > > >>>>>> Burkard
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>> Hey Bukard,
> > > >>>>>
> > > >>>>> This problem is caused because the Hibernate session is closed after
> > > >>>>> the persistence operation completes.
> > > >>>>>
> > > >>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > > >>>>> by default. As far as I understand, Hibernate 3.1 does not open a
> > > >>>>> connection to the database when the session is created, but at the
> > > >>>>> first occurence a connection is needed. Can anyone confirm this? This
> > > >>>>> should solve wasting valuable resources for every request.
> > > >>>>>
> > > >>>>> Steven
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>> Hi Steven,
> > > >>>>
> > > >>>> I thought there was OpenSessionInFilter configured, at least i get an
> > > >>>> Exception where he occurs.
> > > >>>>
> > > >>>> Burkard
> > > >>>>
> > > >>>>    [script] failed to lazily initialize a collection of role:
> > > >>>> User.communications - no session or session was closed
> > > >>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > >>>> initialize a collection of role: User.communications - no session or
> > > >>>> session was closed
> > > >>>>    [script]     at
> > > >>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > >>>>    [script]     at
> > > >>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > >>>>    [script]     at
> > > >>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > >>>>    [script]     at
> > > >>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > >>>> Method)
> > > >>>>    [script]     at
> > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >>>>    [script]     at
> > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> > > >>>>    [script]     at UserController.login(UserController:82)
> > > >>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > > >>>> Source)
> > > >>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > >>>>    [script]     at
> > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > >>>>    [script]     at
> > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > >>>>    [script]     at UserController$_closure2.doCall(UserController:9)
> > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > >>>> Method)
> > > >>>>    [script]     at
> > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >>>>    [script]     at
> > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > >>>>    [script]     at
> > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > >>>>    [script]     at UserController$_closure2.doCall(UserController)
> > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > >>>> Method)
> > > >>>>    [script]     at
> > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > >>>>    [script]     at
> > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > >>>>    [script]     at
> > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
> > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> > > >>>>    [script]     at
> > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> > > >>>>    [script]     at
> > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> > > >>>>    [script]     at
> > > >>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > >>>>    [script]     at
> > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> > > >>>>    [script]     at
> > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > >>>>    [script]     at
> > > >>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> > > >>>>    [script]     at
> > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> > > >>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> > > >>>>    [script]     at
> > > >>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >> --
> > > >> Steven Devijver
> > > >> Senior Consultant
> > > >> Interface21
> > > >> Spring Services from the Source
> > > >> http://www.interface21.com
> > > >>
> > > >> Co-author, "Expert Spring MVC and Web Flow"
> > > >> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > > >> http://www.amazon.com/gp/product/159059584X
> > > >>
> > > >> Interface21 NL B.V.
> > > >> Donker Curtiusstraat 7-400c
> > > >> 1051JL Amsterdam
> > > >> The Netherlands
> > > >> Phone: +31 (0)20 486 47 63
> > > >> Fax: +31 (0)20 475 08 28
> > > >> Mail: [hidden email]
> > > >> Skype: devijvers
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> >
>
>
> --
> Steven Devijver
> Senior Consultant
> Interface21
> Spring Services from the Source
> http://www.interface21.com
>
> Co-author, "Expert Spring MVC and Web Flow"
> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> http://www.amazon.com/gp/product/159059584X
>
> Interface21 NL B.V.
> Donker Curtiusstraat 7-400c
> 1051JL Amsterdam
> The Netherlands
> Phone: +31 (0)20 486 47 63
> Fax: +31 (0)20 475 08 28
> Mail: [hidden email]
> Skype: devijvers
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

graemer
 AopUtils.isAopProxy() returns true :-|

There is no AOP proxy creation in the SpringConfig class, it does use
an extended LocalSessionFactoryBean does this use a proxy?

Graeme

On 06/02/06, Graeme Rocher <[hidden email]> wrote:

> On 06/02/06, Steven Devijver <[hidden email]> wrote:
> > Wrapped in a proxy??!
> >
> > This is the strangest story I've heard all morning.
> >
> > Can you check if it's a Spring AOP proxy? You can cast it to the
> > Advised interface as a test or use AopUtils.isAopProxy().
>
> Ok will try
>
> Graeme
>
> >
> > Steven
> >
> > On 2/6/06, Graeme Rocher <[hidden email]> wrote:
> > > Thanks Burkard.
> > >
> > > Steven I have run the code through a debugger and it seems to be a
> > > problem with the way the SessionFactory is bound the the
> > > TransactionSynchronizationManager. When it is actually bound by the
> > > OpenSessionViewInFilter it uses a map with the sessionfactory as the
> > > key. At the point of binding it is wrapped in a proxy:
> > >
> > > {$Proxy0@4420}org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> > >
> > > Later when it is retrieved by the HibernateTemplate it uses the
> > > SessionFactory as the key again, but it doesn't appear wrapped in a
> > > Proxy:
> > >
> > > org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> > >
> > > As the sessionFactory is the key it and it is dfiferent when wrapped
> > > and not wrapped in the proxy i thinks there is no session bound to the
> > > current thread and closes the session resulting in subsequent calls
> > > having a closed session bound to the thread
> > >
> > > Do you know why this could be happening? I will keep digging..
> > >
> > > Cheers
> > > Graeme
> > >
> > > On 06/02/06, Burkard Endres <[hidden email]> wrote:
> > > > Hi Graeme,
> > > >
> > > > i tried to call from a helper method within a controller.
> > > > This helper method was called by an action within the same controller.
> > > > And first i did a query to database with
> > > > session.user = User.findByUserNameAndPassword(....
> > > > and then i did a System.out in the helpermethod to session.user.userName
> > > > and it printed out the correct name.
> > > > and then i called in the same method session.user.communications and
> > > > then i get the error.
> > > >
> > > > Burkard
> > > >
> > > >
> > > > Graeme Rocher wrote:
> > > > > Ok Thanks Steven,
> > > > >
> > > > > Burkard where are you calling this method is it from a controller? I
> > > > > have a feeling it might be from a bootstrap class in which case the
> > > > > filter would never have been called and hence you would experience
> > > > > this problem
> > > > >
> > > > > Graeme
> > > > >
> > > > > On 05/02/06, Steven Devijver <[hidden email]> wrote:
> > > > >
> > > > >> The filter gets invoked before the servlet is invoked, so everything
> > > > >> that happens inside Spring MVC and Grails should happen in the scope
> > > > >> of the filter, thus also the controller.
> > > > >>
> > > > >> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> > > > >>
> > > > >>> We already have an OpenSessionInViewFilter configured. See
> > > > >>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> > > > >>>
> > > > >>> which extends the Spring one to lookup the sessin factory from the
> > > > >>> grails context
> > > > >>>
> > > > >>> This seems to work when accessing relationships in the view but
> > > > >>> Buckard is accessing it from the controller which is likely the
> > > > >>> problem.. does the filter not cover this Steven? Or does it only open
> > > > >>> the session once spring MVC forwards to the view?
> > > > >>>
> > > > >>> Graeme
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> > > > >>>
> > > > >>>> Steven Devijver wrote:
> > > > >>>>
> > > > >>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>> hi,
> > > > >>>>>>
> > > > >>>>>> i have a two classes
> > > > >>>>>>
> > > > >>>>>> class Communication {
> > > > >>>>>>     @Property Long id;
> > > > >>>>>>     @Property Long version;
> > > > >>>>>>     @Property String type;
> > > > >>>>>>     @Property Boolean active;
> > > > >>>>>>     @Property String defUser;
> > > > >>>>>>     @Property Date   defTime;
> > > > >>>>>>     @Property String modUser;
> > > > >>>>>>     @Property Date modTime;
> > > > >>>>>>
> > > > >>>>>>     @Property String content;
> > > > >>>>>>
> > > > >>>>>>     @Property User user;
> > > > >>>>>>
> > > > >>>>>>     @Property optionals = [ "modUser", "modTime"]
> > > > >>>>>> }
> > > > >>>>>>
> > > > >>>>>> class User  {
> > > > >>>>>>     @Property Long id;
> > > > >>>>>>     @Property Long version;
> > > > >>>>>>     @Property String type;
> > > > >>>>>>     @Property Boolean active;
> > > > >>>>>>     @Property String defUser;
> > > > >>>>>>     @Property Date   defTime;
> > > > >>>>>>     @Property String modUser;
> > > > >>>>>>     @Property Date modTime;
> > > > >>>>>>
> > > > >>>>>>     @Property String userName;
> > > > >>>>>>     @Property String password;
> > > > >>>>>>
> > > > >>>>>>     @Property relationships = ["communications" : Communication.class];
> > > > >>>>>>     @Property optionals = [ "modUser", "modTime"];
> > > > >>>>>>
> > > > >>>>>>     @Property Set communications = new HashSet();
> > > > >>>>>>
> > > > >>>>>>     def void add(toAdd){
> > > > >>>>>>         toAdd.user = this
> > > > >>>>>>         toAdd.active = true
> > > > >>>>>>         toAdd.defTime = new Date()
> > > > >>>>>>         communications.add(toAdd)
> > > > >>>>>>     }
> > > > >>>>>> }
> > > > >>>>>>
> > > > >>>>>> i have successfully inserted some datasets to the database (mysql)
> > > > >>>>>> when i call
> > > > >>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
> > > > >>>>>> user.communications i get an Exception
> > > > >>>>>>    [script] failed to lazily initialize a collection of role:
> > > > >>>>>> User.communications - no session or session was closed
> > > > >>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > > >>>>>> initialize a collection of role: User.communications - no session or
> > > > >>>>>> session was closed
> > > > >>>>>>    [script]     at
> > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > > >>>>>>    [script]     at
> > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > > >>>>>>    [script]     at
> > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > > >>>>>>    [script]     at
> > > > >>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > > >>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > >>>>>> Method)
> > > > >>>>>>
> > > > >>>>>> can any of you tell me what i am doing wrong.
> > > > >>>>>> thanks
> > > > >>>>>>
> > > > >>>>>> Burkard
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>> Hey Bukard,
> > > > >>>>>
> > > > >>>>> This problem is caused because the Hibernate session is closed after
> > > > >>>>> the persistence operation completes.
> > > > >>>>>
> > > > >>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > > > >>>>> by default. As far as I understand, Hibernate 3.1 does not open a
> > > > >>>>> connection to the database when the session is created, but at the
> > > > >>>>> first occurence a connection is needed. Can anyone confirm this? This
> > > > >>>>> should solve wasting valuable resources for every request.
> > > > >>>>>
> > > > >>>>> Steven
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>> Hi Steven,
> > > > >>>>
> > > > >>>> I thought there was OpenSessionInFilter configured, at least i get an
> > > > >>>> Exception where he occurs.
> > > > >>>>
> > > > >>>> Burkard
> > > > >>>>
> > > > >>>>    [script] failed to lazily initialize a collection of role:
> > > > >>>> User.communications - no session or session was closed
> > > > >>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > > >>>> initialize a collection of role: User.communications - no session or
> > > > >>>> session was closed
> > > > >>>>    [script]     at
> > > > >>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > > >>>>    [script]     at
> > > > >>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > > >>>>    [script]     at
> > > > >>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > > >>>>    [script]     at
> > > > >>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > >>>> Method)
> > > > >>>>    [script]     at
> > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >>>>    [script]     at
> > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> > > > >>>>    [script]     at UserController.login(UserController:82)
> > > > >>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > > > >>>> Source)
> > > > >>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > >>>>    [script]     at
> > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > >>>>    [script]     at
> > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > > >>>>    [script]     at UserController$_closure2.doCall(UserController:9)
> > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > >>>> Method)
> > > > >>>>    [script]     at
> > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >>>>    [script]     at
> > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > >>>>    [script]     at
> > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > > >>>>    [script]     at UserController$_closure2.doCall(UserController)
> > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > >>>> Method)
> > > > >>>>    [script]     at
> > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > >>>>    [script]     at
> > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > >>>>    [script]     at
> > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
> > > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> > > > >>>>    [script]     at
> > > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> > > > >>>>    [script]     at
> > > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > >>>>    [script]     at
> > > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> > > > >>>>    [script]     at
> > > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > >>>>    [script]     at
> > > > >>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> > > > >>>>    [script]     at
> > > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> > > > >>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> > > > >>>>    [script]     at
> > > > >>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >> --
> > > > >> Steven Devijver
> > > > >> Senior Consultant
> > > > >> Interface21
> > > > >> Spring Services from the Source
> > > > >> http://www.interface21.com
> > > > >>
> > > > >> Co-author, "Expert Spring MVC and Web Flow"
> > > > >> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > > > >> http://www.amazon.com/gp/product/159059584X
> > > > >>
> > > > >> Interface21 NL B.V.
> > > > >> Donker Curtiusstraat 7-400c
> > > > >> 1051JL Amsterdam
> > > > >> The Netherlands
> > > > >> Phone: +31 (0)20 486 47 63
> > > > >> Fax: +31 (0)20 475 08 28
> > > > >> Mail: [hidden email]
> > > > >> Skype: devijvers
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
> > --
> > Steven Devijver
> > Senior Consultant
> > Interface21
> > Spring Services from the Source
> > http://www.interface21.com
> >
> > Co-author, "Expert Spring MVC and Web Flow"
> > (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > http://www.amazon.com/gp/product/159059584X
> >
> > Interface21 NL B.V.
> > Donker Curtiusstraat 7-400c
> > 1051JL Amsterdam
> > The Netherlands
> > Phone: +31 (0)20 486 47 63
> > Fax: +31 (0)20 475 08 28
> > Mail: [hidden email]
> > Skype: devijvers
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

graemer
Burkard this should be fixed now in CVS head

Cheers
Graeme

On 06/02/06, Graeme Rocher <[hidden email]> wrote:

>  AopUtils.isAopProxy() returns true :-|
>
> There is no AOP proxy creation in the SpringConfig class, it does use
> an extended LocalSessionFactoryBean does this use a proxy?
>
> Graeme
>
> On 06/02/06, Graeme Rocher <[hidden email]> wrote:
> > On 06/02/06, Steven Devijver <[hidden email]> wrote:
> > > Wrapped in a proxy??!
> > >
> > > This is the strangest story I've heard all morning.
> > >
> > > Can you check if it's a Spring AOP proxy? You can cast it to the
> > > Advised interface as a test or use AopUtils.isAopProxy().
> >
> > Ok will try
> >
> > Graeme
> >
> > >
> > > Steven
> > >
> > > On 2/6/06, Graeme Rocher <[hidden email]> wrote:
> > > > Thanks Burkard.
> > > >
> > > > Steven I have run the code through a debugger and it seems to be a
> > > > problem with the way the SessionFactory is bound the the
> > > > TransactionSynchronizationManager. When it is actually bound by the
> > > > OpenSessionViewInFilter it uses a map with the sessionfactory as the
> > > > key. At the point of binding it is wrapped in a proxy:
> > > >
> > > > {$Proxy0@4420}org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> > > >
> > > > Later when it is retrieved by the HibernateTemplate it uses the
> > > > SessionFactory as the key again, but it doesn't appear wrapped in a
> > > > Proxy:
> > > >
> > > > org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> > > >
> > > > As the sessionFactory is the key it and it is dfiferent when wrapped
> > > > and not wrapped in the proxy i thinks there is no session bound to the
> > > > current thread and closes the session resulting in subsequent calls
> > > > having a closed session bound to the thread
> > > >
> > > > Do you know why this could be happening? I will keep digging..
> > > >
> > > > Cheers
> > > > Graeme
> > > >
> > > > On 06/02/06, Burkard Endres <[hidden email]> wrote:
> > > > > Hi Graeme,
> > > > >
> > > > > i tried to call from a helper method within a controller.
> > > > > This helper method was called by an action within the same controller.
> > > > > And first i did a query to database with
> > > > > session.user = User.findByUserNameAndPassword(....
> > > > > and then i did a System.out in the helpermethod to session.user.userName
> > > > > and it printed out the correct name.
> > > > > and then i called in the same method session.user.communications and
> > > > > then i get the error.
> > > > >
> > > > > Burkard
> > > > >
> > > > >
> > > > > Graeme Rocher wrote:
> > > > > > Ok Thanks Steven,
> > > > > >
> > > > > > Burkard where are you calling this method is it from a controller? I
> > > > > > have a feeling it might be from a bootstrap class in which case the
> > > > > > filter would never have been called and hence you would experience
> > > > > > this problem
> > > > > >
> > > > > > Graeme
> > > > > >
> > > > > > On 05/02/06, Steven Devijver <[hidden email]> wrote:
> > > > > >
> > > > > >> The filter gets invoked before the servlet is invoked, so everything
> > > > > >> that happens inside Spring MVC and Grails should happen in the scope
> > > > > >> of the filter, thus also the controller.
> > > > > >>
> > > > > >> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> > > > > >>
> > > > > >>> We already have an OpenSessionInViewFilter configured. See
> > > > > >>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> > > > > >>>
> > > > > >>> which extends the Spring one to lookup the sessin factory from the
> > > > > >>> grails context
> > > > > >>>
> > > > > >>> This seems to work when accessing relationships in the view but
> > > > > >>> Buckard is accessing it from the controller which is likely the
> > > > > >>> problem.. does the filter not cover this Steven? Or does it only open
> > > > > >>> the session once spring MVC forwards to the view?
> > > > > >>>
> > > > > >>> Graeme
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> > > > > >>>
> > > > > >>>> Steven Devijver wrote:
> > > > > >>>>
> > > > > >>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > > > > >>>>>
> > > > > >>>>>
> > > > > >>>>>> hi,
> > > > > >>>>>>
> > > > > >>>>>> i have a two classes
> > > > > >>>>>>
> > > > > >>>>>> class Communication {
> > > > > >>>>>>     @Property Long id;
> > > > > >>>>>>     @Property Long version;
> > > > > >>>>>>     @Property String type;
> > > > > >>>>>>     @Property Boolean active;
> > > > > >>>>>>     @Property String defUser;
> > > > > >>>>>>     @Property Date   defTime;
> > > > > >>>>>>     @Property String modUser;
> > > > > >>>>>>     @Property Date modTime;
> > > > > >>>>>>
> > > > > >>>>>>     @Property String content;
> > > > > >>>>>>
> > > > > >>>>>>     @Property User user;
> > > > > >>>>>>
> > > > > >>>>>>     @Property optionals = [ "modUser", "modTime"]
> > > > > >>>>>> }
> > > > > >>>>>>
> > > > > >>>>>> class User  {
> > > > > >>>>>>     @Property Long id;
> > > > > >>>>>>     @Property Long version;
> > > > > >>>>>>     @Property String type;
> > > > > >>>>>>     @Property Boolean active;
> > > > > >>>>>>     @Property String defUser;
> > > > > >>>>>>     @Property Date   defTime;
> > > > > >>>>>>     @Property String modUser;
> > > > > >>>>>>     @Property Date modTime;
> > > > > >>>>>>
> > > > > >>>>>>     @Property String userName;
> > > > > >>>>>>     @Property String password;
> > > > > >>>>>>
> > > > > >>>>>>     @Property relationships = ["communications" : Communication.class];
> > > > > >>>>>>     @Property optionals = [ "modUser", "modTime"];
> > > > > >>>>>>
> > > > > >>>>>>     @Property Set communications = new HashSet();
> > > > > >>>>>>
> > > > > >>>>>>     def void add(toAdd){
> > > > > >>>>>>         toAdd.user = this
> > > > > >>>>>>         toAdd.active = true
> > > > > >>>>>>         toAdd.defTime = new Date()
> > > > > >>>>>>         communications.add(toAdd)
> > > > > >>>>>>     }
> > > > > >>>>>> }
> > > > > >>>>>>
> > > > > >>>>>> i have successfully inserted some datasets to the database (mysql)
> > > > > >>>>>> when i call
> > > > > >>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
> > > > > >>>>>> user.communications i get an Exception
> > > > > >>>>>>    [script] failed to lazily initialize a collection of role:
> > > > > >>>>>> User.communications - no session or session was closed
> > > > > >>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > > > >>>>>> initialize a collection of role: User.communications - no session or
> > > > > >>>>>> session was closed
> > > > > >>>>>>    [script]     at
> > > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > > > >>>>>>    [script]     at
> > > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > > > >>>>>>    [script]     at
> > > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > > > >>>>>>    [script]     at
> > > > > >>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > > > >>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > >>>>>> Method)
> > > > > >>>>>>
> > > > > >>>>>> can any of you tell me what i am doing wrong.
> > > > > >>>>>> thanks
> > > > > >>>>>>
> > > > > >>>>>> Burkard
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>> Hey Bukard,
> > > > > >>>>>
> > > > > >>>>> This problem is caused because the Hibernate session is closed after
> > > > > >>>>> the persistence operation completes.
> > > > > >>>>>
> > > > > >>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > > > > >>>>> by default. As far as I understand, Hibernate 3.1 does not open a
> > > > > >>>>> connection to the database when the session is created, but at the
> > > > > >>>>> first occurence a connection is needed. Can anyone confirm this? This
> > > > > >>>>> should solve wasting valuable resources for every request.
> > > > > >>>>>
> > > > > >>>>> Steven
> > > > > >>>>>
> > > > > >>>>>
> > > > > >>>>>
> > > > > >>>> Hi Steven,
> > > > > >>>>
> > > > > >>>> I thought there was OpenSessionInFilter configured, at least i get an
> > > > > >>>> Exception where he occurs.
> > > > > >>>>
> > > > > >>>> Burkard
> > > > > >>>>
> > > > > >>>>    [script] failed to lazily initialize a collection of role:
> > > > > >>>> User.communications - no session or session was closed
> > > > > >>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > > > >>>> initialize a collection of role: User.communications - no session or
> > > > > >>>> session was closed
> > > > > >>>>    [script]     at
> > > > > >>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > > > >>>>    [script]     at
> > > > > >>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > > > >>>>    [script]     at
> > > > > >>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > > > >>>>    [script]     at
> > > > > >>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > >>>> Method)
> > > > > >>>>    [script]     at
> > > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > >>>>    [script]     at
> > > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> > > > > >>>>    [script]     at UserController.login(UserController:82)
> > > > > >>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > > > > >>>> Source)
> > > > > >>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > > >>>>    [script]     at
> > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > > >>>>    [script]     at
> > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > > > >>>>    [script]     at UserController$_closure2.doCall(UserController:9)
> > > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > >>>> Method)
> > > > > >>>>    [script]     at
> > > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > >>>>    [script]     at
> > > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > > >>>>    [script]     at
> > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > > > >>>>    [script]     at UserController$_closure2.doCall(UserController)
> > > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > >>>> Method)
> > > > > >>>>    [script]     at
> > > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > >>>>    [script]     at
> > > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > > >>>>    [script]     at
> > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
> > > > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> > > > > >>>>    [script]     at
> > > > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> > > > > >>>>    [script]     at
> > > > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > > >>>>    [script]     at
> > > > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> > > > > >>>>    [script]     at
> > > > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > > >>>>    [script]     at
> > > > > >>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> > > > > >>>>    [script]     at
> > > > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> > > > > >>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> > > > > >>>>    [script]     at
> > > > > >>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >> --
> > > > > >> Steven Devijver
> > > > > >> Senior Consultant
> > > > > >> Interface21
> > > > > >> Spring Services from the Source
> > > > > >> http://www.interface21.com
> > > > > >>
> > > > > >> Co-author, "Expert Spring MVC and Web Flow"
> > > > > >> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > > > > >> http://www.amazon.com/gp/product/159059584X
> > > > > >>
> > > > > >> Interface21 NL B.V.
> > > > > >> Donker Curtiusstraat 7-400c
> > > > > >> 1051JL Amsterdam
> > > > > >> The Netherlands
> > > > > >> Phone: +31 (0)20 486 47 63
> > > > > >> Fax: +31 (0)20 475 08 28
> > > > > >> Mail: [hidden email]
> > > > > >> Skype: devijvers
> > > > > >>
> > > > > >>
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> > > --
> > > Steven Devijver
> > > Senior Consultant
> > > Interface21
> > > Spring Services from the Source
> > > http://www.interface21.com
> > >
> > > Co-author, "Expert Spring MVC and Web Flow"
> > > (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > > http://www.amazon.com/gp/product/159059584X
> > >
> > > Interface21 NL B.V.
> > > Donker Curtiusstraat 7-400c
> > > 1051JL Amsterdam
> > > The Netherlands
> > > Phone: +31 (0)20 486 47 63
> > > Fax: +31 (0)20 475 08 28
> > > Mail: [hidden email]
> > > Skype: devijvers
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with getting relationsships out of database

Guillaume Laforge-2
And thanks for reporting this problem and helping us improving Grails!
We're looking forward to looking at your contributions.

Guillaume


On 07/02/06, Graeme Rocher <[hidden email]> wrote:

> Burkard this should be fixed now in CVS head
>
> Cheers
> Graeme
>
> On 06/02/06, Graeme Rocher <[hidden email]> wrote:
> >  AopUtils.isAopProxy() returns true :-|
> >
> > There is no AOP proxy creation in the SpringConfig class, it does use
> > an extended LocalSessionFactoryBean does this use a proxy?
> >
> > Graeme
> >
> > On 06/02/06, Graeme Rocher <[hidden email]> wrote:
> > > On 06/02/06, Steven Devijver <[hidden email]> wrote:
> > > > Wrapped in a proxy??!
> > > >
> > > > This is the strangest story I've heard all morning.
> > > >
> > > > Can you check if it's a Spring AOP proxy? You can cast it to the
> > > > Advised interface as a test or use AopUtils.isAopProxy().
> > >
> > > Ok will try
> > >
> > > Graeme
> > >
> > > >
> > > > Steven
> > > >
> > > > On 2/6/06, Graeme Rocher <[hidden email]> wrote:
> > > > > Thanks Burkard.
> > > > >
> > > > > Steven I have run the code through a debugger and it seems to be a
> > > > > problem with the way the SessionFactory is bound the the
> > > > > TransactionSynchronizationManager. When it is actually bound by the
> > > > > OpenSessionViewInFilter it uses a map with the sessionfactory as the
> > > > > key. At the point of binding it is wrapped in a proxy:
> > > > >
> > > > > {$Proxy0@4420}org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> > > > >
> > > > > Later when it is retrieved by the HibernateTemplate it uses the
> > > > > SessionFactory as the key again, but it doesn't appear wrapped in a
> > > > > Proxy:
> > > > >
> > > > > org.hibernate.impl.SessionFactoryImpl@1d0eb0b
> > > > >
> > > > > As the sessionFactory is the key it and it is dfiferent when wrapped
> > > > > and not wrapped in the proxy i thinks there is no session bound to the
> > > > > current thread and closes the session resulting in subsequent calls
> > > > > having a closed session bound to the thread
> > > > >
> > > > > Do you know why this could be happening? I will keep digging..
> > > > >
> > > > > Cheers
> > > > > Graeme
> > > > >
> > > > > On 06/02/06, Burkard Endres <[hidden email]> wrote:
> > > > > > Hi Graeme,
> > > > > >
> > > > > > i tried to call from a helper method within a controller.
> > > > > > This helper method was called by an action within the same controller.
> > > > > > And first i did a query to database with
> > > > > > session.user = User.findByUserNameAndPassword(....
> > > > > > and then i did a System.out in the helpermethod to session.user.userName
> > > > > > and it printed out the correct name.
> > > > > > and then i called in the same method session.user.communications and
> > > > > > then i get the error.
> > > > > >
> > > > > > Burkard
> > > > > >
> > > > > >
> > > > > > Graeme Rocher wrote:
> > > > > > > Ok Thanks Steven,
> > > > > > >
> > > > > > > Burkard where are you calling this method is it from a controller? I
> > > > > > > have a feeling it might be from a bootstrap class in which case the
> > > > > > > filter would never have been called and hence you would experience
> > > > > > > this problem
> > > > > > >
> > > > > > > Graeme
> > > > > > >
> > > > > > > On 05/02/06, Steven Devijver <[hidden email]> wrote:
> > > > > > >
> > > > > > >> The filter gets invoked before the servlet is invoked, so everything
> > > > > > >> that happens inside Spring MVC and Grails should happen in the scope
> > > > > > >> of the filter, thus also the controller.
> > > > > > >>
> > > > > > >> On 2/5/06, Graeme Rocher <[hidden email]> wrote:
> > > > > > >>
> > > > > > >>> We already have an OpenSessionInViewFilter configured. See
> > > > > > >>> http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/modules/grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate/support/GrailsOpenSessionInViewFilter.java
> > > > > > >>>
> > > > > > >>> which extends the Spring one to lookup the sessin factory from the
> > > > > > >>> grails context
> > > > > > >>>
> > > > > > >>> This seems to work when accessing relationships in the view but
> > > > > > >>> Buckard is accessing it from the controller which is likely the
> > > > > > >>> problem.. does the filter not cover this Steven? Or does it only open
> > > > > > >>> the session once spring MVC forwards to the view?
> > > > > > >>>
> > > > > > >>> Graeme
> > > > > > >>>
> > > > > > >>>
> > > > > > >>>
> > > > > > >>> On 05/02/06, Burkard Endres <[hidden email]> wrote:
> > > > > > >>>
> > > > > > >>>> Steven Devijver wrote:
> > > > > > >>>>
> > > > > > >>>>> On 2/5/06, Burkard Endres <[hidden email]> wrote:
> > > > > > >>>>>
> > > > > > >>>>>
> > > > > > >>>>>> hi,
> > > > > > >>>>>>
> > > > > > >>>>>> i have a two classes
> > > > > > >>>>>>
> > > > > > >>>>>> class Communication {
> > > > > > >>>>>>     @Property Long id;
> > > > > > >>>>>>     @Property Long version;
> > > > > > >>>>>>     @Property String type;
> > > > > > >>>>>>     @Property Boolean active;
> > > > > > >>>>>>     @Property String defUser;
> > > > > > >>>>>>     @Property Date   defTime;
> > > > > > >>>>>>     @Property String modUser;
> > > > > > >>>>>>     @Property Date modTime;
> > > > > > >>>>>>
> > > > > > >>>>>>     @Property String content;
> > > > > > >>>>>>
> > > > > > >>>>>>     @Property User user;
> > > > > > >>>>>>
> > > > > > >>>>>>     @Property optionals = [ "modUser", "modTime"]
> > > > > > >>>>>> }
> > > > > > >>>>>>
> > > > > > >>>>>> class User  {
> > > > > > >>>>>>     @Property Long id;
> > > > > > >>>>>>     @Property Long version;
> > > > > > >>>>>>     @Property String type;
> > > > > > >>>>>>     @Property Boolean active;
> > > > > > >>>>>>     @Property String defUser;
> > > > > > >>>>>>     @Property Date   defTime;
> > > > > > >>>>>>     @Property String modUser;
> > > > > > >>>>>>     @Property Date modTime;
> > > > > > >>>>>>
> > > > > > >>>>>>     @Property String userName;
> > > > > > >>>>>>     @Property String password;
> > > > > > >>>>>>
> > > > > > >>>>>>     @Property relationships = ["communications" : Communication.class];
> > > > > > >>>>>>     @Property optionals = [ "modUser", "modTime"];
> > > > > > >>>>>>
> > > > > > >>>>>>     @Property Set communications = new HashSet();
> > > > > > >>>>>>
> > > > > > >>>>>>     def void add(toAdd){
> > > > > > >>>>>>         toAdd.user = this
> > > > > > >>>>>>         toAdd.active = true
> > > > > > >>>>>>         toAdd.defTime = new Date()
> > > > > > >>>>>>         communications.add(toAdd)
> > > > > > >>>>>>     }
> > > > > > >>>>>> }
> > > > > > >>>>>>
> > > > > > >>>>>> i have successfully inserted some datasets to the database (mysql)
> > > > > > >>>>>> when i call
> > > > > > >>>>>> user = User.findByUserNameAndPassword(<username>,<password>)
> > > > > > >>>>>> user.communications i get an Exception
> > > > > > >>>>>>    [script] failed to lazily initialize a collection of role:
> > > > > > >>>>>> User.communications - no session or session was closed
> > > > > > >>>>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > > > > >>>>>> initialize a collection of role: User.communications - no session or
> > > > > > >>>>>> session was closed
> > > > > > >>>>>>    [script]     at
> > > > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > > > > >>>>>>    [script]     at
> > > > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > > > > >>>>>>    [script]     at
> > > > > > >>>>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > > > > >>>>>>    [script]     at
> > > > > > >>>>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > > > > >>>>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > > >>>>>> Method)
> > > > > > >>>>>>
> > > > > > >>>>>> can any of you tell me what i am doing wrong.
> > > > > > >>>>>> thanks
> > > > > > >>>>>>
> > > > > > >>>>>> Burkard
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>> Hey Bukard,
> > > > > > >>>>>
> > > > > > >>>>> This problem is caused because the Hibernate session is closed after
> > > > > > >>>>> the persistence operation completes.
> > > > > > >>>>>
> > > > > > >>>>> Guys, I think it makes sense to configure the OpenSessionInViewFilter
> > > > > > >>>>> by default. As far as I understand, Hibernate 3.1 does not open a
> > > > > > >>>>> connection to the database when the session is created, but at the
> > > > > > >>>>> first occurence a connection is needed. Can anyone confirm this? This
> > > > > > >>>>> should solve wasting valuable resources for every request.
> > > > > > >>>>>
> > > > > > >>>>> Steven
> > > > > > >>>>>
> > > > > > >>>>>
> > > > > > >>>>>
> > > > > > >>>> Hi Steven,
> > > > > > >>>>
> > > > > > >>>> I thought there was OpenSessionInFilter configured, at least i get an
> > > > > > >>>> Exception where he occurs.
> > > > > > >>>>
> > > > > > >>>> Burkard
> > > > > > >>>>
> > > > > > >>>>    [script] failed to lazily initialize a collection of role:
> > > > > > >>>> User.communications - no session or session was closed
> > > > > > >>>>    [script] org.hibernate.LazyInitializationException: failed to lazily
> > > > > > >>>> initialize a collection of role: User.communications - no session or
> > > > > > >>>> session was closed
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
> > > > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > > >>>> Method)
> > > > > > >>>>    [script]     at
> > > > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > > >>>>    [script]     at
> > > > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.Invoker.asIterator(Invoker.java:423)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:155)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.asIterator(ScriptBytecodeAdapter.java:383)
> > > > > > >>>>    [script]     at UserController.login(UserController:82)
> > > > > > >>>>    [script]     at gjdk.UserController_GroovyReflector.invoke(Unknown
> > > > > > >>>> Source)
> > > > > > >>>>    [script]     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > > > >>>>    [script]     at
> > > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > > > >>>>    [script]     at
> > > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:312)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > > > > >>>>    [script]     at UserController$_closure2.doCall(UserController:9)
> > > > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > > >>>> Method)
> > > > > > >>>>    [script]     at
> > > > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > > >>>>    [script]     at
> > > > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > > > >>>>    [script]     at
> > > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
> > > > > > >>>>    [script]     at UserController$_closure2.doCall(UserController)
> > > > > > >>>>    [script]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > > > > > >>>> Method)
> > > > > > >>>>    [script]     at
> > > > > > >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > > > > > >>>>    [script]     at
> > > > > > >>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > > > > > >>>>    [script]     at java.lang.reflect.Method.invoke(Method.java:585)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:636)
> > > > > > >>>>    [script]     at
> > > > > > >>>> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
> > > > > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:176)
> > > > > > >>>>    [script]     at groovy.lang.Closure.call(Closure.java:171)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:315)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:267)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:113)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:79)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
> > > > > > >>>>    [script]     at
> > > > > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:596)
> > > > > > >>>>    [script]     at
> > > > > > >>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:427)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:830)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewFilter.doFilterInternal(GrailsOpenSessionInViewFilter.java:78)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > > > >>>>    [script]     at
> > > > > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
> > > > > > >>>>    [script]     at
> > > > > > >>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:180)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1565)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:635)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.http.HttpContext.handle(HttpContext.java:1517)
> > > > > > >>>>    [script]     at org.mortbay.http.HttpServer.service(HttpServer.java:954)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:983)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> > > > > > >>>>    [script]     at
> > > > > > >>>> org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >> --
> > > > > > >> Steven Devijver
> > > > > > >> Senior Consultant
> > > > > > >> Interface21
> > > > > > >> Spring Services from the Source
> > > > > > >> http://www.interface21.com
> > > > > > >>
> > > > > > >> Co-author, "Expert Spring MVC and Web Flow"
> > > > > > >> (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > > > > > >> http://www.amazon.com/gp/product/159059584X
> > > > > > >>
> > > > > > >> Interface21 NL B.V.
> > > > > > >> Donker Curtiusstraat 7-400c
> > > > > > >> 1051JL Amsterdam
> > > > > > >> The Netherlands
> > > > > > >> Phone: +31 (0)20 486 47 63
> > > > > > >> Fax: +31 (0)20 475 08 28
> > > > > > >> Mail: [hidden email]
> > > > > > >> Skype: devijvers
> > > > > > >>
> > > > > > >>
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Steven Devijver
> > > > Senior Consultant
> > > > Interface21
> > > > Spring Services from the Source
> > > > http://www.interface21.com
> > > >
> > > > Co-author, "Expert Spring MVC and Web Flow"
> > > > (February 2006, with Seth Ladd, Darren Davison, and Keith Donald)
> > > > http://www.amazon.com/gp/product/159059584X
> > > >
> > > > Interface21 NL B.V.
> > > > Donker Curtiusstraat 7-400c
> > > > 1051JL Amsterdam
> > > > The Netherlands
> > > > Phone: +31 (0)20 486 47 63
> > > > Fax: +31 (0)20 475 08 28
> > > > Mail: [hidden email]
> > > > Skype: devijvers
> > > >
> > >
> >
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy