Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 542847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:29:22+00:00 2026-05-13T10:29:22+00:00

I’ve upgraded a Grails 1.0.4 application to 1.1.1. After upgrading, I’m repeatedly getting Exceptions

  • 0

I’ve upgraded a Grails 1.0.4 application to 1.1.1. After upgrading, I’m repeatedly getting Exceptions when executing my Quartz jobs (using Quartz plugin 0.4.1). The plugin is used to manually schedule jobs using Simple and Cron Triggers via a service (paraphrased code below):

class SchedulerService implements InitializingBean
{
    static scope = 'singleton'
    ...
    def schedule(def batch) {
        JobDetail job = new JobDetail(uniqueId, groupName, BatchJob.class, false, false, true)
        job.jobDataMap.put("batchId", batch.id)

        SimpleTrigger trigger = new SimpleTrigger(triggerId, triggerGroup, 0)

        SchedulerFactory factory = new SchedulerFactory()
        factory.initialize(properties)
        Scheduler scheduler = factory.getScheduler()

        scheduler.scheduleJob(job, trigger)
    }
    ...
}

My BatchJob job is set up as follows:

class BatchJob implements Job, InterruptableJob
{
    static triggers = {}
    void execute(JobExecutionContext context) {
        def batch = Batch.get(context.jobDetail.jobDataMap.getLongValue("batchId"))
        // the next line is "line 49" from the stack trace below
        def foo = batch.batchStatus.description
    }
}

Here’s an abbreviated definition of Batch.groovy (domain):

class Batch
{
    BatchStatus batchStatus // relationship
}

However, when schedulerService.schedule() is invoked with an existing, saved Batch, I receive 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:311)
        at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil$unwrapProxy.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        ...
        <b>at BatchJob.execute(BatchJob.groovy:49)</b>
        ...

I’ve tried the following actions to fix this, but none have worked:

  • I’ve specified static fetchMode = [batchStatus: 'eager'] on my Batch domain class
  • I’ve used static mapping = { columns { batchStatus lazy:false }} on my Batch domain class
  • I’ve tried using batch.attach() after calling Batch.get() in the Job

I can’t use BatchJob.triggerNow() in this instance, because this is only one of a couple examples – the others are still scheduled by the service, but might be scheduled as a cron job or otherwise. I should mention that I did upgrade the Quartz plugin as well when upgrading Grails; the previous Quartz version was 0.4.1-SNAPSHOT (as opposed to the upgraded version, just 0.4.1).

How do I get Hibernate sessions to work correctly in these manually-triggered Quartz Jobs?

I’ve also sent this question to the grails-user mailing list, as for a more niche issue like this, the list seems to elicit a bit more response. I’ll update this question with an answer if one comes out of there. Here’s a link.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:29:22+00:00Added an answer on May 13, 2026 at 10:29 am

    Check out jira issue 165 (http://jira.codehaus.org/browse/GRAILSPLUGINS-165) There are also clues in the Quartz Plugin (which you may like to check out) This code was used with the JMS plugin which seems to work well.

    try

        import org.hibernate.FlushMode
        import org.hibernate.Session
        import org.springframework.orm.hibernate3.SessionFactoryUtils
        import org.springframework.orm.hibernate3.SessionHolder
    
        class BatchJob implements Job, InterruptableJob
        {
            static triggers = {}
            void execute(JobExecutionContext context) {
               Session session = null;   
               try { 
                  session = SessionFactoryUtils.getSession(sessionFactory, false); 
               }
               // If not already bound the Create and Bind it! 
               catch (java.lang.IllegalStateException ex) { 
                  session = SessionFactoryUtils.getSession(sessionFactory, true);  
                  TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); 
               }
              session.setFlushMode(FlushMode.AUTO);
              if( log.isDebugEnabled()) log.debug("Hibernate Session is bounded to Job thread");
    
            // Your Code!
            def batch = Batch.get(context.jobDetail.jobDataMap.getLongValue("batchId"))
            // the next line is "line 49" from the stack trace below
            def foo = batch.batchStatus.description
    
    
    
            try {
             SessionHolder sessionHolder = (SessionHolder) 
             TransactionSynchronizationManager.unbindResource(sessionFactory);
             if(!FlushMode.MANUAL.equals(sessionHolder.getSession().getFlushMode())) {
               sessionHolder.getSession().flush(); 
             }
             SessionFactoryUtils.closeSession(sessionHolder.getSession());
             if( log.isDebugEnabled()) log.debug("Hibernate Session is unbounded from Job thread and closed");
           }
           catch (Exception ex) { 
             ex.printStackTrace(); 
           }
       }
    }
    

    Hope this helps. It worked for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.