nimo23
nimo23

Reputation: 5680

quarkus: hibernate entityManger with inject

According to Quarkus Documentation, we can inject a thread safe entityManger by @Inject.

@ApplicationScoped
public class SantaClausService {
    @Inject
    EntityManager em; 

    @Transactional 
    public void createGift(String giftDescription) {
        Gift gift = new Gift();
        gift.setName(giftDescription);
        em.persist(gift);
    }
}

However, when I do so, the warning:

No bean is eligible for injection to the injection point

comes.

When trying to compile, I get this error:

Caused by: javax.enterprise.inject.UnsatisfiedResolutionException:
Unsatisfied dependency for type javax.persistence.EntityManager 
and qualifiers [@Default]

This means, I must qualify the injected entityManger by an annotation which I must create and assign to that entityManager. This would not be needed in jee with @PersistenceContext EntityManager em.

Is there any prepared entityManager in Quarkus which is already qualified and ready to use without warnings?

Upvotes: 0

Views: 718

Answers (1)

pL4Gu33
pL4Gu33

Reputation: 2085

Has your Gift a @Entity annotation?

This error is a bit misleading. If you have no @Entity class you will get this error, too.

I tried it... without @Entity get the error, then i add @Entity to class everything works fine.

Upvotes: 1

Related Questions