In the JSR 352 batch specification there are some issues around transactions with JCA. These issues would mainly be seen with JDBC item readers/writers.

Here is kind of a thought dump from a sit down I had with the JCA team. If anyone has any opinions on how this should be handled let's talk it out. I would imagine this is a fairly important issue as generally speaking batch jobs will likely be legacy jobs and JDBC is probably heavily used.



Batch Transactions with JCA

Problem:
Batch requires that a Transaction.begin() and a Transaction.commit() for each open, close and chunk processed. This causes connections from JCA to potentially cross transactional boundaries.
    This requires that the JCA CachedConnectionManager (CCM) is enabled for the resource in question (Jesper)

Transaction code should be written like:
Connection c
Transaction.begin()
c = DataSource.getConnection()
c.close()
Transaction.commit()

Chunk Processing process:
Transaction.begin()
ItemReader.open()
ItemWriter.open()
Transaction.commit()

repeat until item reader returns null
    Transaction.begin()
    repeat-on-chunk
        ItemReader.readItem()
        ItemProcessor.processItem()
    ItemWriter.writeItems
    Transaction.commit()

Transaction.begin()
ItemReader.close()
ItemWriter.close()
Transaction.commit()

Where seen:

Questions:


Possible Fixes:
Example JBoss Way
repeat until item reader returns null
    Transaction.begin()
    ItemReader.open()
    ItemWriter.open()
    repeat-on-chunk
        ItemReader.readItem()
        ItemProcessor.processItem()
    ItemWriter.writeItems()
    ItemReader.close()
    ItemWriter.close()
    Transaction.commit()



-- 
James R. Perkins
JBoss by Red Hat