Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] Session-related problems in a service

Antoine Roux

2010-03-15

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,
I have a problem with the Hibernate session. I am using Cometd plug-in
and in a Grails service, I just want to log some information about users
that are doing comet requests. I get the logged in user thanks to spring
Security's authenticateService. But I also have to access a property
that is on the other side of a one-to-one relationship:

/**
* Method called each time a new client arrives
*/
public void clientAdded(Client client) {
   
    def user = authenticateService.userDomain()
    if (user) {
          clients.put(client.id, ["client": client,
                          "ipbxId": user.ipbx.name])
     
          }
}

The problem occurs when trying to read user.ipbx. Ipbx is a domain class
that is associated to User on a one-on-one relationship. I get the
following exception:

org.hibernate.LazyInitializationException: could not initialize proxy -
no Session
  at
org.hibernate.proxy.AbstractLazyInitializer.initialize (AbstractLazyInitializer.java:86)
  at
org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil.unwrapProxy (GrailsHibernateUtil.java:321)
  at
org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil$unwrapProxy.call(Unknown
Source)
[...]


I tried wrapping the call in withSession / withNewSession /
withTransaction, but the error remains. I did not find a workaround on
the mailing list history. I am using Grails 1.2.1.

I already had the problem a while ago with a Quartz job, but I found a
mean to do things differently. It looks like in Grails 1.2 there is a
something different with requests on domain objects that are done
outside of the usual request path or in threads.

Do you have a solution for this?

Thanks,


Antoine

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

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.