@Transactional rollbackFor not working on jboss wildfly
@Transactional rollbackFor not working on jboss wildfly
我有一个用 @Transactional(rollbackFor = CustomerRollBackException.class) 注释的方法,当我在嵌入 tomcat 中测试它时,它按预期工作。
但是,我将它部署在 jboss wildfly 上,同样的方法在抛出异常时没有进行回滚。
您是否知道 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");
}
..
它正在进入第一个 catch 并抛出 CustomerRollBackException 并且回滚未执行。
我认为 jboss 你应该改用 rollbackOn
解决方案:
在 jboss 上配置数据源并在应用程序中使用它
spring.datasource.jndi-name=java:/XXXX
而不是:
spring.datasource.url= jdbc:
spring.datasource.username=
spring.datasource.password=
我有一个用 @Transactional(rollbackFor = CustomerRollBackException.class) 注释的方法,当我在嵌入 tomcat 中测试它时,它按预期工作。 但是,我将它部署在 jboss wildfly 上,同样的方法在抛出异常时没有进行回滚。 您是否知道 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");
}
..
它正在进入第一个 catch 并抛出 CustomerRollBackException 并且回滚未执行。
我认为 jboss 你应该改用 rollbackOn
解决方案: 在 jboss 上配置数据源并在应用程序中使用它 spring.datasource.jndi-name=java:/XXXX 而不是:
spring.datasource.url= jdbc:
spring.datasource.username=
spring.datasource.password=