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

  • Quartz jobs in Spring losing sessions and throwing LazyInitializationException s


    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

    	<!-- ========================================================================================= -->
    	<!-- CONFIG -->
    	<!-- ========================================================================================= -->
        <bean class="" />
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">     
            <property name="dataSource" ref="dataSource" />
      		<property name="persistenceUnitName" value="soccer" />     
            <property name="jpaVendorAdapter">
                    <property name="database" value="MYSQL" />
                    <property name="showSql" value="false" />
        <bean lazy-init="false" id="dataSource"
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost/$$$$" />
            <property name="username" value="$$$$" />
            <property name="password" value="$$$$" />                
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        <tx:annotation-driven transaction-manager="transactionManager" />
    	<!-- ========================================================================================= -->
    	<!-- QUARTZ-->
    	<!-- ========================================================================================= --> 
    	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    	    <property name="triggers">
    	            <ref bean="importResultsTrigger" />
      		<property name="applicationContextSchedulerContextKey"><value>applicationContext</value></property>
    	<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  name="importResults" class="org.springframework.scheduling.quartz.JobDetailBean">
      		<property name="jobClass" value="" />

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