Hi, below is a sample with what I believe are the pertinent config items.
Just to add, the persistence unit definition in persistence.xml doesn't specify anything other than the beans to persist so I have not included it.
I suspect the answer will lay in the configuration of hibernate and how to stop it interfering with the transaction but I haven't found anything in their docs to help me yet.
Code:
<step
id="xWriter">
<tasklet>
<chunk
reader="xReader"
processor="xProcessor"
writer="jpaItemWriter"
commit-interval="1">
</chunk>
<listeners>
<listener
ref="xLoggingListener" />
</listeners>
</tasklet>
</step>
<bean
id="jpaItemWriter"
class="org.springframework.batch.item.database.JpaItemWriter">
<property
name="entityManagerFactory"
ref="emf" />
</bean>
<bean
id="jpaTemplate"
class="org.springframework.orm.jpa.JpaTemplate">
<constructor-arg>
<ref
bean="emf" />
</constructor-arg>
</bean>
<bean
id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property
name="entityManagerFactory"
ref="emf" />
</bean>
<bean
id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property
name="dataSource"
ref="dataSource" />
<property
name="persistenceUnitName"
value="persistenceUnit" />
<property
name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property
name="showSql"
value="${database.showSql}" />
</bean>
</property>
<property
name="jpaProperties">
<props>
<prop key="hibernate.dialect">${database.hibernateDialect}</prop>
<prop key="hibernate.order_inserts">true</prop>
<prop key="hibernate.default_batch_fetch_size">999</prop>
<prop key="hibernate.jdbc.fetch_size">1000</prop>
<prop key="hibernate.jdbc.batch_size">500</prop>
</props>
</property>
<property
name="jpaDialect">
<!-- https://jira.springframework.org/browse/SPR-5012 -->
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<beans:bean
id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
p:dataSource-ref="dataSource"
p:transactionManager-ref="transactionManager"
p:isolationLevelForCreate="ISOLATION_DEFAULT"
p:lobHandler-ref="${database.lobHandler}" />