Quartz Plugin

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.4.1
  • Fix Version/s: 0.4.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP 2000
    Grails 1.2
    Grails-Hibernate 1.2.0

Description

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

Issue Links

Activity

Hide
Vitalii Samolovskikh added a comment -

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

Show
Vitalii Samolovskikh added a comment - This issue duplicate previous 1807 http://jira.codehaus.org/browse/GRAILSPLUGINS-1807
Hide
Thomas Frieling added a comment -

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

Show
Thomas Frieling added a comment - 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

People

Vote (11)
Watch (11)

Dates

  • Created:
    Updated:
    Resolved: