4

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

Suule
  • 2,197
  • 4
  • 16
  • 42
  • can you please add the code for your custom `@Transaction` annotation? Did you try your code without this annotation? – rieckpil Mar 17 '20 at 06:44
  • @rieckpil I added code. Yes I did try to run without annotation, but it does not help. Probably maybe there is problem with service which I am injecting, something is not working toghether – Suule Mar 17 '20 at 16:47

0 Answers0