`@Transactional` 在 JBoss WildFly 上无法正常工作,回滚操作失效。

huangapple go评论68阅读模式
英文:

@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&lt;Object&gt; rows, UserDTO user
		Iterator iterator;

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

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=

huangapple
  • 本文由 发表于 2020年10月20日 00:00:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64431051.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定