标题翻译
Failure while notifying an observer of event null - when trying to fire event on transaction failure
问题
我需要在交易失败时得到通知的可能性。为此,我创建了事件观察者:
public class TransactionObserver {
private static final Logger log = Logger.getLogger(TransactionObserver.class);
@PersistenceContext(unitName = PERSISTENCE_NAME)
private EntityManager em;
//在正常工作时删除此行
@Inject
private SomeService someService;
public void observeAfterTransactionFailed(@Observes(during = TransactionPhase.AFTER_FAILURE) @Transaction Long id) {
log.error("Message from within transaction received after failure: " + id);
CustomEntity obj = em.find(CustomEntity.class, id);
someService.onTimeoutMarkAsFinished(id);
}
}
除非我删除了注入的服务,否则这是无法正常工作的。我得到了以下错误:
ERROR [org.jboss.weld.Event] (Transaction Reaper Worker 0) WELD-000401: 在通知事件 null 的观察者时失败
该事件是从以下方法中触发的:
@Asynchronous
@TransactionTimeout(value = 1, unit = TimeUnit.SECONDS)
public void doStuff() {
simpleMessageEvent.fire(stepId);
.
.
}
您知道有什么问题吗,或者如何获取更多信息/日志?
编辑:
交易代码:
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
public @interface Transaction {
}
删除此注解没有帮助。
英文翻译
I need possibility to be informed when transaction has failed. And for that case I did create Event observer:
public class TransactionObserver {
private static final Logger log = Logger.getLogger(TransactionObserver.class);
@PersistenceContext(unitName = PERSISTENCE_NAME)
private EntityManager em;
//remove it to work correctly
@Inject
private SomeService someService;
public void observeAfterTransactionFailed(@Observes(during = TransactionPhase.AFTER_FAILURE) @Transaction Long id) {
log.error("Message from within transaction received after failure: " + id);
CustomEntity obj= em.find(CustomEntity.class, id);
someService.onTimeoutMarkAsFinished(id);
}
And this is not working unless I remove injected service. I am getting following error:
ERROR [org.jboss.weld.Event] (Transaction Reaper Worker 0) WELD-000401: Failure while notifying an observer of event null
Event is fired from method like this:
@Asynchronous
@TransactionTimeout(value = 1, unit = TimeUnit.SECONDS)
public void doStuff() {
simpleMessageEvent.fire(stepId);
.
.
}
Any idea what is wrong or how could I get more information/logs?
edit:
Transaction code:
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
public @interface Transaction {
}
Removing this annotation is not helping
专注分享java语言的经验与见解,让所有开发者获益!
评论