Search code examples
javaspring-bootjpatransactionsrollback

@Transactional rollbackFor not working on jboss wildfly


I have a method annotated with @Transactional(rollbackFor = CustomerRollBackException.class) and it is working as expected when I test it in embebed tomcat. However, I have it deployed on a jboss wildfly, and the same method is not doing the rollback when it throw the exception.. Do you have any idea if is needed any configuration on jboss?

    @Override
    @Transactional(rollbackFor = CustomerRollBackException.class)
    public void importGenericTable(SheetDTO sheetDTO) throws Exception {
        // String tableName, List<Object> rows, UserDTO user
        Iterator iterator;

        String tableName = sheetDTO.getTableName();
....
try{
..
} catch (ParseException | PersistenceException | SQLGrammarException | ConstraintViolationException e) {
            logger.error("importGenericTable. Error " + e);
            throw new CustomerRollBackException("E_NPRO_UTIL_IMPORT_0001:" + (countRows + 2));
        } catch (CustomerNotFoundException e) {
            throw new CustomerRollBackException(e.getMessage());
        } catch (Exception e) {
            throw new CustomerRollBackException("error desconocido");
        }
..

It's entering in the first catch and throwing the CustomerRollBackException and the rollback is not executing.


Solution

  • Solution : Configure datasource on jboss and use it in the application using spring.datasource.jndi-name=java:/XXXX instead of :

    spring.datasource.url= jdbc:
    spring.datasource.username=
    spring.datasource.password=