Hi,
I have HttpSessionListener to listen for when sessions are created and destroyed. I have a user domain which has loggedIn boolean column which I update whenever user logs in or logs out which I use for admin management. I also store the session Id in the database.
I also want to update the loggedIn column whenever the session is destroyed. Below is the code written in the sessionDestroyed method.
def user = User.findByUserSessionId(session.getId())
if(user) {
user.setLoggedIn(false)
user.setUserSessionId("SESSION DESTROYED")
user.save(flush: true)
}
The problem is the user table never gets updated.
Below is the error reported in log file:
[2010-10-16 11:45:07.781] ERROR core.ContainerBase.[Tomcat].[localhost].[/SAMPLE] Session event listener threw exception
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
at org.codehaus.groovy.grails.orm.hibernate.validation.HibernateDomainClassValidator.validate(HibernateDomainClassValidator.java:66)
at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.doInvokeInternal(AbstractSavePersistentMethod.java:129)
at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:59)
at sun.reflect.GeneratedMethodAccessor500.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:188)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132)
at org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport$_addBasicPersistenceMethods_closure71.doCall(HibernatePluginSupport.groovy:812)
Can I know how the proper way to update the user table when session is destroyed.
Thank You. Jay Chandran.