'quarkus - switching from "default" to "PersistenceUnit" causes "Unsatisfied dependency"

Quarkus 2.7.4

I had my app working with default datasource config. When I tried to switch to using persistence units it stopped working. I've got to the point where I get this error...

[ERROR]         [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.persistence.EntityManager and qualifiers [@PersistenceUnit(value = "ds")] 
[ERROR]         - java member: uk.co.me.filter.CheckFilter#entityManager 
[ERROR]         - declared on CLASS bean [types=[uk.co.me.filter.CheckFilter, javax.ws.rs.container.ContainerRequestFilter, java.lang.Object], qualifiers=[@Default, @Any], target=uk.co.me.filter.CheckFilter] 
[ERROR]         The following beans match by type, but none have matching qualifiers: 
[ERROR]                 - Bean [class=org.hibernate.Session, qualifiers=[@javax.enterprise.inject.Default, @Any]]

What am I missing?.

I had my default config working...

quarkus:
  datasource:
    db-kind: mssql 
    username: user 
    password: pwd 
    jdbc: 
      url: jdbc:sqlserver://localhost:1433

Then I tried to convert it to a persistent unit...

quarkus:
  datasource:
    ds:
      db-kind: mssql
      username: user
      password: pwd
      jdbc:
        url: jdbc:sqlserver://localhost:1433
  hibernate-orm:
    datasource: ds
    packages: uk.co.me.filter

And I added the annotation to my class

@Inject @PersistenceUnit("ds") EntityManager entityManager;

First it complained about couldn't find default models so I added the original config back in. That resolved the error (I realise not the best, but hey, just trying to get things moving). Now I get the above error when trying to build the quarkus-run.jar



Solution 1:[1]

On the configuration snippet you add, you only configure a ds named datasource but not a ds named persistence unit so only the default one exist.

You need to configure Hibernate ORM or multiple persistence unit as explained here: https://quarkus.io/guides/hibernate-orm#multiple-persistence-units

In your case something like this:

quarkus:
  datasource:
    ds:
      db-kind: mssql
      username: user
      password: pwd
      jdbc:
        url: jdbc:sqlserver://localhost:1433
  hibernate-orm:
    ds:
      datasource: ds
      packages: uk.co.me.filter

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 loicmathieu