EJB/JPA batch process exception management-Collection of common programming errors
Here is my problem. I work on a synchronization batch using 2 EJB/JPA/Hibernate modules.
The first module reads information in the database A and detects changes. Once detected, modified items are sent to the second module through JMS.
The second module reads the message and iterates through the modified items and updates information in the database B.
Once the update process is finished, a message containing the ID of the items successfully updated is sent to the first module who flags in the database A the successfully updated items.
All the process works but I don’t know how to manage exception that could occur during the persistence process using the container managed EntityManager.
If I wasn’t working with a container managed EntityManager I would open a new transaction for each insert and commit it or rollback it depending if any exception occurred.
I need to know when an exception occurred in order not to add the id of the item being currently processed, and causing an exception, in the list with the id of the items successfully updated. Also, if I’m processing 10 items and that the first one in the list creates an exception I need to continue with the other 9 items.
I thought that using @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) in front of the persistent methods would solve my issue but it didn’t.
Is there a way to do what I need to do using a container managed EntityManager?
Thank you.