英文:
@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,但回滚未被执行。
英文:
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.
答案1
得分: 0
我认为使用jboss时,你应该使用rollbackOn而不是。
英文:
I think with jboss you should use rollbackOn instead
答案2
得分: 0
解决方案:
在 JBoss 上配置数据源,并在应用程序中使用以下方式使用它:
spring.datasource.jndi-name=java:/XXXX
而不是:
spring.datasource.url=jdbc:
spring.datasource.username=
spring.datasource.password=
英文:
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=
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论