Issue Details (XML | Word | Printable)

Key: GRAILSPLUGINS-1808
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Sergey Nebolsin
Reporter: Andriy Binetskyy
Votes: 11
Watchers: 11
Operations

If you were logged in you would be able to see more operations.
Grails Plugins

Hibernate "No Hibernate Session bound to thread..." in Quartz Job after upgrading to Grails 1.2

Created: 29/Dec/09 03:45 AM   Updated: 26/Feb/10 02:47 PM   Resolved: 26/Feb/10 02:47 PM
Component/s: Grails-Quartz
Affects Version/s: Grails-Quartz 0.4.1
Fix Version/s: Grails-Quartz 0.4.2

Time Tracking:
Not Specified

Environment:
Windows XP 2000
Grails 1.2
Grails-Hibernate 1.2.0
Issue Links:
dependent
 


 Description  « Hide

There is a Quartz Job, that changes a Domain Object with default database connection.
Since upgrade to Grails 1.2 a Hibernate Exception is coming.
Setting def sessionRequired = false doesn't have any effect.

2009-12-29 10:30:16,008 [quartzScheduler_Worker-6] ERROR core.ErrorLogger - Unable to notify JobListener(s) of Job that was executed: (error will be ignored).
trigger= GRAILS_JOBS.DoAllJob job= GRAILS_JOBS.DoAllJob
org.quartz.SchedulerException: JobListener 'sessionBinderListener' threw exception: No Hibernate Session bound to thread, and configuration does not allow creat
ion of non-transactional one here [See nested exception: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allo
w creation of non-transactional one here]
at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1912)
at org.quartz.core.JobRunShell.notifyJobListenersComplete(JobRunShell.java:355)
at org.quartz.core.JobRunShell.run(JobRunShell.java:226)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: 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:70)
at org.codehaus.groovy.grails.validation.GrailsDomainClassValidator.validate(GrailsDomainClassValidator.java:144)
at org.codehaus.groovy.grails.orm.hibernate.metaclass.ValidatePersistentMethod.doInvokeInternal(ValidatePersistentMethod.java:101)
at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
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:133)
at org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport$_addValidationMethods_closure19.doCall(HibernatePluginSupport.groovy:496)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:81)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:307)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:63)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor.onPreUpdate(ClosureEventTriggeringInterceptor.groovy:160)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:88)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.codehaus.groovy.grails.orm.hibernate.events.PatchedDefaultFlushEventListener.performExecutions(PatchedDefaultFlushEventListener.java:44)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.codehaus.groovy.grails.plugins.quartz.listeners.SessionBinderJobListener.jobWasExecuted(SessionBinderJobListener.java:58)
at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1910)
... 3 more



Vitaliy Samolovskih added a comment - 29/Dec/09 05:54 AM

This issue duplicate previous 1807
http://jira.codehaus.org/browse/GRAILSPLUGINS-1807


Thomas Frieling added a comment - 27/Jan/10 08:45 AM

Actually I do not think this is a duplicate - the solution described in #1807 also does not work for me...

In my case the described problem happens when saving domain objects within services during job execution. To workaround this problem we added a flush/clear to the end of each job execution:

def myService

def execute() {
    myService.doSomeStuff()
    // ...
    sessionFactory?.getCurrentSession().flush()
    sessionFactory?.getCurrentSession().clear()
}

Maybe flush/clear should be called in SessionBinderJobListener.jobWasExecuted(...) as the first thing to be done?

Let me know your thoughts...

Best Regards,
Thomas