Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails 3.0.15 & Quartz: No Session Found For Current Thread #75

Closed
ilan18 opened this issue Aug 23, 2016 · 4 comments
Closed

Grails 3.0.15 & Quartz: No Session Found For Current Thread #75

ilan18 opened this issue Aug 23, 2016 · 4 comments

Comments

@ilan18
Copy link

ilan18 commented Aug 23, 2016

Using Grails 3.0.15. From Quartz calling Grails Service, which explicitly calls domain class withTransaction. Getting error "No Session found for current thread". See stack traceback below:

2016-08-23 14:43:37.147 [QuartzScheduler2_Worker-12] ERROR com.the.company.name.TheQuartzJob - _execute_closure2 threw unexpected throwable (Heuristic completion: outcome state is mixed; nested exception is org.springframework.orm.hibernate4.HibernateSystemException: No Session found for current thread; nested exception is org.hibernate.HibernateException: No Session found for current thread).  Marking job as failed
org.springframework.transaction.HeuristicCompletionException: Heuristic completion: outcome state is mixed; nested exception is org.springframework.orm.hibernate4.HibernateSystemException: No Session found for current thread; nested exception is org.hibernate.HibernateException: No Session found for current thread
        at org.grails.transaction.ChainedTransactionManager.commit(ChainedTransactionManager.java:174) ~[ChainedTransactionManager.class:3.0.11]
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:150) ~[TransactionTemplate.class:4.1.8.RELEASE]
        at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) ~[GrailsTransactionTemplate.class:3.0.11]
        at org.grails.datastore.gorm.GormStaticApi.withTransaction(GormStaticApi.groovy:822) ~[GormStaticApi.class:na]
        at org.grails.datastore.gorm.GormStaticApi.withTransaction(GormStaticApi.groovy:722) ~[GormStaticApi.class:na]
        at org.grails.datastore.gorm.GormStaticApi$withTransaction$2.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[CallSiteArray.class:2.4.5]
        at org.grails.datastore.gorm.GormStaticApi$withTransaction$2.call(Unknown Source) ~[na:na]
        at org.grails.datastore.gorm.GormEntity$Trait$Helper.withTransaction(GormEntity.groovy:724) ~[GormEntity$Trait$Helper.class:na]
        at org.grails.datastore.gorm.GormEntity$Trait$Helper$withTransaction$1.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[CallSiteArray.class:2.4.5]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[AbstractCallSite.class:2.4.5]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) ~[AbstractCallSite.class:2.4.5]
        at com.the.company.name.directory.Contact.withTransaction(Contact.groovy) ~[Contact.class:na]
        at com.the.company.name.directory.Contact$withTransaction$5.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[CallSiteArray.class:2.4.5]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[AbstractCallSite.class:2.4.5]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[AbstractCallSite.class:2.4.5]

Have tried:

  • One or both of withSession() withNewSession() withTransaction() and withNewTransaction() in varying places in the code calling hierarchy
  • Using @Tranactional on various Services methods

The project has similar code from Quartz calling withTransaction() successfully. No idea what is different about this one and why this one does not work.

  • Operating System: Same issue seen when resulting war deployed in Windows 10 and Linux
  • Grails Version: 3.0.15
  • JDK Version: 1.7.0_79
  • Container Version (If Applicable): Tomcat 8.0.14
@rvanderwerf
Copy link
Contributor

Which version of the plugin are you using? You need to make sure you enable the Quartz plugin Config to enable hibernate support.

@ilan18
Copy link
Author

ilan18 commented Aug 24, 2016

Quartz Plugin 2.0.9

There are other Quartz jobs that are working correctly accessing the database. I have not been able to identify what is different in this one case.

@davydotcom
Copy link
Contributor

happens because of quartz startup order.. it will correct itself on next execution but if there is a job right at the beginning it will try to execute before hibernate session has been injected ... super annoying bug

davydotcom added a commit to davydotcom/grails-quartz that referenced this issue Mar 28, 2017
…as starting up too early and not spring artifact aware or session bind aware. Also fixes shutdown to properly shutdown before the session gets wiped out from underneath
davydotcom added a commit that referenced this issue Mar 28, 2017
#86)

* Resolves issue #71 , probably #75 and #34. Quartz was starting up too early and not spring artifact aware or session bind aware. Also fixes shutdown to properly shutdown before the session gets wiped out from underneath

* deleting rogue commented code
@davydotcom
Copy link
Contributor

2.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants