【发布时间】:2017-02-01 20:49:39
【问题描述】:
我不明白为什么在新事务中抛出 RuntimeException 时不会发生回滚。
我的 MDB:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/adwordsReportRequest"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "veiculo = 'teste'"),
@ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue = "10"),})
public class TesteMDB implements MessageListener {
@Resource
private MessageDrivenContext mdc;
@Inject
private ReportExtractor reportExtractor;
@Inject
private Logger logger;
public TesteMDB() {
// TODO Auto-generated constructor stub
}
public void onMessage(Message inMessage) {
try {
runReport();
} catch (Exception e) {
logger.error("Pega erro: {}", e.getMessage());
e.printStackTrace();
}
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
private void runReport() throws Exception {
reportExtractor.RunTest();
}
}
其他类:
@RequestScoped
public class ReportExtractor {
@Inject
JMSMessageManager jmsMessagerManager;
@Inject
private Logger logger;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void RunTest() throws Exception {
//insert in Queue
jmsMessagerManager.sendMessage("test");
throw new RuntimeException("test - runtime");
}
}
当我在第二个中使用 @Stateful 时,它可以工作。
如果不是 SessionBean,那么就不是
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
创建一个新交易?还是只有基于 RuntimeException 的自动回滚不起作用?
谢谢,
【问题讨论】:
标签: java jakarta-ee jta