Announcement Announcement Module
Collapse
No announcement yet.
JPA Transaction Manager with multiple entity manager factories Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA Transaction Manager with multiple entity manager factories

    Hi,

    I have a job that reads from one database and writes to another, so both reader and writer are using different entity manager factories.....

    Code:
    <job id="loadAdviceScheduleJob" xmlns="http://www.springframework.org/schema/batch">
    <step id="step1 ">
    	<tasklet transaction-manager="transactionManager">
    		<chunk reader="AdviceScheduleReader" processor="AdviceScheduleProcessor" writer="AdviceScheduleWriter"
    					commit-interval="10" />
    				
    			</tasklet>
    		</step>
    	</job>
    
                <bean id="AdviceScheduleReader"
    		class="org.springframework.batch.item.database.JpaPagingItemReader">
    		<property name="entityManagerFactory" ref="AS400entityManagerFactory" />
    		<property name="queryString" value="select a from Adsphy01 a" />
    	</bean>
    
    	<bean id="AdviceScheduleWriter" class="org.springframework.batch.item.database.JpaItemWriter">
    		<property name="entityManagerFactory" ref="DB2entityManagerFactory" />
    	</bean>
    Now the question is how do we define the transaction manager...

    Code:
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="DB2entityManagerFactory" />
    	</bean>
    Right now it looks like JpaTransactionManager can only work with 1 entityManagerFactory.

    Thanks for any help.

  • #2
    Have a look at this thread towards the bottom.

    http://forum.springsource.org/showth...h-Spring-Batch

    Comment


    • #3
      Originally posted by Jehan99 View Post
      Hi,

      I have a job that reads from one database and writes to another, so both reader and writer are using different entity manager factories.....

      Code:
      <job id="loadAdviceScheduleJob" xmlns="http://www.springframework.org/schema/batch">
      <step id="step1 ">
      	<tasklet transaction-manager="transactionManager">
      		<chunk reader="AdviceScheduleReader" processor="AdviceScheduleProcessor" writer="AdviceScheduleWriter"
      					commit-interval="10" />
      				
      			</tasklet>
      		</step>
      	</job>
      
                  <bean id="AdviceScheduleReader"
      		class="org.springframework.batch.item.database.JpaPagingItemReader">
      		<property name="entityManagerFactory" ref="AS400entityManagerFactory" />
      		<property name="queryString" value="select a from Adsphy01 a" />
      	</bean>
      
      	<bean id="AdviceScheduleWriter" class="org.springframework.batch.item.database.JpaItemWriter">
      		<property name="entityManagerFactory" ref="DB2entityManagerFactory" />
      	</bean>
      Now the question is how do we define the transaction manager...

      Code:
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      		<property name="entityManagerFactory" ref="DB2entityManagerFactory" />
      	</bean>
      Right now it looks like JpaTransactionManager can only work with 1 entityManagerFactory.

      Thanks for any help.
      you may want to use something like Bitronix or Atomikos. Or, if you're running always in a container, use the transaction manager of the container.

      See this article for more details http://blog.springsource.org/2011/08...-full-java-ee/

      Comment

      Working...
      X