Announcement Announcement Module
No announcement yet.
JpaPagingItemReader in Weblogic Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JpaPagingItemReader in Weblogic

    I have a scenario where I need to read about 500 000 Entities from DB and create new entity for each + update couple status attributes in those 500 000 read. I need to run my batch jobs in Oracle WLS 11g and with JTA. I tried JpaPagingItemReader but it fails to start transaction. So I created my own modification of reader in which the entitymanager published in jndi is injected to reader with @PersistenceContext and doReadPage is annotated with Transactional(REQUIRES_NEW). So it does not create entitymanager via entitymanagerFactory in doOpen anymore and there's not anymore programmatic transaction handling in that method. This works at least with single threaded step execution in WLS. But in this case also the writers use the same entitymanager. So I am worried if there can be deadlocks in the db and whether my solution would be thread safe, because for that amount of data I need to run step with multiple threads.

    Is there any way to use of the self JPAPagingItemReader with JTA?

    I have used remote chunking with some of my jobs (with more data to handle) already, but I was hoping this could be handled with pure Spring Batch job.
    Last edited by _es; Mar 24th, 2010, 02:08 PM.

  • #2
    You aren't very precise about why it doesn't work in the first place. Is there an exception?


    • #3
      Sorry, I wrote that in a hurry.

      With JpaPagingItemReader I get this exception:

      Exception Description: Cannot use an EntityTransaction while using JTA.
      at org.eclipse.persistence.internal.jpa.transaction.J TATransactionWrapper.getTransaction(JTATransaction
      at org.eclipse.persistence.internal.jpa.EntityManager Impl.getTransaction(
      at org.springframework.batch.item.database.JpaPagingI temReader.doReadPage(

      And my entityManger + transactionManger conf looks like this:

      	<bean id="transactionManager"
      		class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" />
      	<jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/pContext" />
      And similar exception comes also with OpenJPA as persistence provider.
      Last edited by _es; Mar 29th, 2010, 12:45 AM.


      • #4
        You probably need to configure the EntityManagerFactory in Spring not in JNDI to make it work as expected. If you don't do that then I'm not sure Spring acn manage the transactions at all in fact, but this reader is a special case because it uses the EntityManager transaction API directly.


        • #5
          The batch jobs are deployed as a part of ear in which there's also EJBs and Mdbs which use the same JPA-Daos as the batch jobs. The Daos inject the entitymanager with @PersistenceContext annotation. I have thought that I get the EJB and Mdb transaction management "integrated" with the Spring transactions by using the jndi entitymanagerfactory and JTATransactionManager as defined in reference manual:

          BTW, as a workaround I am now using JdbcPagingItemReader to read the data from DB and then write is delegated to Daos which handle the data updates with JPA. And it works well.