Search code examples
jpaquarkusentitylisteners

Injection in entity listener with Quarkus


I'm trying to inject a bean into an entity listener in a Quarkus-application:

@ApplicationScoped
public class MyEntityListener implements Serializable {

    @Inject
    MyService service;

    @PrePersist
    @PreUpdate
    public void checkWrite(BaseEntity entity) {
        service.check(entity);
    }
}

But service is always null. Changing scope to @SessionScoped has no effect.

According to this 2 SO-discussions, this should be possible:

I couldn't find any information about which JPA-version Quarkus is using, but since it is a state-of-the-art-framework I think it is JPA 2.1?

So should this be possible and if yes, what am I doing wrong?


Solution

  • I found a Quarkus-issue addressing this problem: https://github.com/quarkusio/quarkus/issues/6948

    Seems like Quarkus is lacking support for this feature and maybe it will be implemented in the future. There's also a workaround described.