-
1. Re: Java batch (JSR352), JPA and chunk transactions problem
jamezp May 15, 2014 3:25 PM (in response to fantarama)1 of 1 people found this helpfulIn the batch spec each read, process and write is done in a separate transaction. If you use the same EntityManager in multiple chunks the connection persists across transaction boundaries. IMO for EE the batch spec is broken. If you're on WildFly 8.1.x however you can add a property jberet.local-tx with a value of true to your job properties, step configuration in the job.xml or the job configuration in the job.xml. This will use a local transaction instead of the enlisted transaction and hibernate should take care of the transaction boundaries.
--
James R. Perkins
-
2. Re: Re: Java batch (JSR352), JPA and chunk transactions problem
fantarama May 16, 2014 5:28 AM (in response to jamezp)Thank you,
the problem is that the transaction is not active even in the single write chunk, I'm not looking for a transaction across read and write; my code:
@PersistenceContext
EntityManager em;
@Override
public void writeItems(List<Object> items) throws Exception {
for (Object i : items) {
MyEntity e = new MyEntity();
... some code ...
em.persist(e);
}
}
The above code insert and commit the entity on each loop iteration instead of the end of the method. If an exception occur iside the loop entities persisted in previous iteration didn't rollback.
I don't need a custom transaction management, I need to understand why there is no transaction at all!
-
3. Re: Java batch (JSR352), JPA and chunk transactions problem
fantarama May 16, 2014 8:26 AM (in response to fantarama)UPDATE
With a new Wildfly installation and reconfiguring the datasource, the tranasctions work. May be an issue related to JTA datasource configuration with mysql?
-
4. Re: Java batch (JSR352), JPA and chunk transactions problem
fantarama May 16, 2014 10:52 AM (in response to fantarama)** SOLVED **
The problem source was the Entity id strategy: set to IDENTITY Hibernate with MySQL do the insert after the persist method, with AUTO or a manual set the inserts sql are flushed at the end of the transaction.
Now my question is: is this a know scenario or i've found some kind of bug?