Post transaction hook

Is there a way to define a post transaction hook instead of using the standard @PostPersist/Update/Delete but to keep the event like created/updated/deleted?

I’m using a redis (don’t know if should mention it now after the license change, but I have done it now :sweat_smile:) and would like to update its content only when the transaction has been completed, when all the cascaded data has been update/created/deleted.

P.S. I do know that Hibernate search has something similar for their indexing needs with elastic/opensearch.

Just going to answer this myself :upside_down_face:, found the documentation with some lucky keywords after writing this jakarta ee - Check whether a JTA transaction is successfully committed - Stack Overflow and after that found a lot more help in the quarkus code.
Using transactions in Quarkus - 3.8 - Quarkus
Add support for transactional observer event · Issue #2224 · quarkusio/quarkus · GitHubIntroduce transactional observer support by manovotn · Pull Request #6581 · quarkusio/quarkus · GitHub
Support event handle after/before transactional commited · Issue #22961 · quarkusio/quarkus · GitHub

Not marking it as a solution yet since I haven’t tried to implement it.

So what I needed wasn’t that hard but and was the JTA transaction handeling, but I had a hard time finding an implementation reference for how it works.

  1. First i needed to create a jakarta event private jakarta.enterprise.event.Event<se.agreedSkiing.example.Entity1> dbLogEvent;
  2. Then fire said event from a @PostPersist/PrePersist
    @jakarta.persistence.PostRemove
    public void sendEvents(se.agreedSkiing.example.Entity1 entity) {
        dbLogEvent.fire(entity);
    }
  1. Create an observer method with the correct transaction phase and wait for a db event to fire.
    void afterSuccessfulTransactionObservingEntity1LogAsJson(
        @jakarta.enterprise.event.Observes(during = jakarta.enterprise.event.TransactionPhase.AFTER_SUCCESS) Entity1 dto
    ) {
        try {
            var json = new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(dto);
            System.out.println(json);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }