Announcement Announcement Module
Collapse
No announcement yet.
Quartz jobs in Spring losing sessions and throwing LazyInitializationException s Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz jobs in Spring losing sessions and throwing LazyInitializationException s

    Hi,

    I know this seems to be a common problem and have done a bit of reading but have failed to find a comprehensive clean solution to my problem.

    The app is a web application that also runs some batch jobs from quartz in the web container. I use OpenEntityManagerInViewFilter and everything is fine in that respect.

    When the quartz jobs get run it starts throwing LazyInitializationExceptions I know exactly why it is happening as the session gets dropped and my objects are holding proxies but I am really looking to find out how to keep the session open for the duration of the quartz job.

    I have placed lazy-init on all the beans but that does not change anything.

    If the worst comes to the worst I can always get the batch to call a URL which runs the batch but that is a bit messy. I thikn that should solve the problem

    IF I knew another way to run the batch jobs which would make this problem go away I would be happy to refactor, I'm just at the point now of foogling for answers.

    Anyway here is the config, any help would be greatly appreciated. Thanks


    Code:
    	<!-- ========================================================================================= -->
    	<!-- CONFIG -->
    	<!-- ========================================================================================= -->
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">     
            <property name="dataSource" ref="dataSource" />
      		<property name="persistenceUnitName" value="soccer" />     
            <property name="jpaVendorAdapter">
                <bean
                    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="database" value="MYSQL" />
                    <property name="showSql" value="false" />
                </bean>
            </property>
        </bean>
    
        <bean lazy-init="false" id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost/$$$$" />
            <property name="username" value="$$$$" />
            <property name="password" value="$$$$" />                
         </bean>
         
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
    
        <tx:annotation-driven transaction-manager="transactionManager" />
        
    	<!-- ========================================================================================= -->
    	<!-- QUARTZ-->
    	<!-- ========================================================================================= --> 
    	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    	    <property name="triggers">
    	        <list>
    	            <ref bean="importResultsTrigger" />
    	        </list>
    	    </property>
      		<property name="applicationContextSchedulerContextKey"><value>applicationContext</value></property>
    	</bean>	
    	     
    	<bean  id="importResultsTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    	    <property name="jobDetail" ref="importResults" />
    	    <property name="startDelay" value="0" />
    	    <property name="repeatInterval" value="36000000" />         
    	</bean>
    
        <bean  name="importResults" class="org.springframework.scheduling.quartz.JobDetailBean">
      		<property name="jobClass" value="com.soccer.timer.ImportResults" />
        </bean>

  • #2
    Just curious, David any luck with this? I just started foogling as you said..

    Comment

    Working...
    X