Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
Quartz scheduler problem need help Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz scheduler problem need help

    We are having some problem with the Quartz scheduler and opensessionviewFilter
    The configuration is descibed below
    <bean name="notificationSchedulerBean" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass">
    <value>core.service.scheduler.NotificationSchedule r</value>
    <property name="jobDataAsMap">
    <entry key="timeout">
    <entry key="schedulerJobDetailsDAO">
    <ref bean="SchedulerJobDetailsDAO" />
    <entry key="applicationSettingDAO">
    <ref bean="ApplicationSettingDAO" />
    <entry key="mailerServiceManager">
    <ref bean="mailerServiceManager" />
    <entry key="repeatInterval">
    <!-- 15 mins In Milli Seconds.Ensure Repeat Interval and Refresh Interval should be same-->
    <ref bean="repeatInterval" />
    <entry key="environment">
    <ref bean="Environment" />
    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
    <property name="jobDetail">
    <!-- see the example of method invoking job above -->
    <ref bean="notificationSchedulerBean" />
    <property name="startDelay">
    <!--15 mins (In milli seconds )-->
    <property name="repeatInterval">
    <!--15 mins (In milli seconds )-->
    <ref bean="repeatInterval" />
    <bean id="repeatInterval" class="java.lang.Long">
    <bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
    <property name="triggers">
    <ref bean="simpleTrigger" />

    <!-- HibernateTemplate configuration -->
    <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.Hibernat eTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    <!-- DAO config -->
    <bean id="ApplicationSettingDAO"
    abstract="false" singleton="true" lazy-init="default"
    autowire="default" dependency-check="default">
    <property name="hibernateTemplate">
    <ref bean="hibernateTemplate" />
    <!-- OpenSessionViewFilter in Web.xml Setup -->
    org.springframework.web.context.ContextLoaderServl et
    This filter overwrites OpenSessionInViewFilter to make flush
    mode to COMMIT.

    When we deploy the application to tomcat or weblogic 9.2
    If i don't open the application URL say for 15 mins (Which is the start delay for scheduler)
    The scheduler kicksoff and the scheduler works fine.
    As soon as i hit a Url of the application, from then on scheduler throws exception saying unable to open connection as the connection is already closed.
    When i open the application just after the deployment, then the scheduler starts after 15 mins, it doesn't complain about the connection or the hibernate session.

    public class ApplicationSessionFilter extends OpenSessionInViewFilter {

    public ApplicationSessionFilter() {
    Logger.log(this, "OpenSessionInViewFilter... Initialised...");
    protected Session getSession(SessionFactory sessionFactory)
    throws DataAccessResourceFailureException {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    Logger.log(this, "ApplicationSessionFilter.getSession() invoked...");
    return session;

    * we do an explicit flush here just in case we do not have an automated
    * flush
    protected void closeSession(Session session, SessionFactory factory) {
    super.closeSession(session, factory);
    Logger.log(this, "ApplicationSessionFilter.closeSession() invoked...");


    Am i missing something here.

  • #2
    Its more than 10 days, no answer yet..
    Can anyone help me in solving this....


    • #3
      Consider using HibernateInterceptor instead

      Im not even going to read your post, you should use the code tags so that it is readable. This works for me:

        <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
           <property name="sessionFactory">
             <ref bean="sessionFactory"/>
       <bean id="backgroundJobTemplate"
          <property name="transactionAttributes">
              <prop key="*">PROPAGATION_REQUIRED</prop>
          <property name="transactionManager" ref="transactionManager"/>
          <property name="preInterceptors" ref="hibernateInterceptor"/>
        <bean id="backgroundJob" parent="backgroundJobTemplate">
          <property name="target">
            <bean class=""/>
        <bean id="backgroundJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
          <property name="targetObject" ref="backgroundJob"/>
          <property name="targetMethod" value="run"/>
      That way your not tied into your hibernate session being bound to the life of the request object (which is why your session is being closed when the response has been rendered upon hitting the URL), rather to the life of the job itself.