JPA - Exception Handling

> JPA - Java Persistence API (JPA)

1 - Code

try {
    this.em.getTransaction().begin();
 
    // JPA tasks
 
    this.em.getTransaction().commit();
    LOGGER.info("All good");
 
} catch (Exception e) {
    LOGGER.warning("Oeps Exception");
    this.em.getTransaction().rollback();
}

2 - Support

2.1 - Transaction rolled back because transaction was set to RollbackOnly.

This is caused when you commit a transaction that was not successful. Just use the rollback function in your catch block in order to restore the transaction.

jpa/exception.txt · Last modified: 2014/01/07 16:37 by gerardnico