1
votes

I have tried @PersistenceContext, @PersistenceUnit, and @Inject combinations but nothing works. @Inject fails maven-quarkus-plugin build:

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

I have tried with and without persistence.xml. My datasource and application.properties work fine, as I can just inject a AgroalDataSource and do direct JDBC, but I want to port over my JPA Entity classes and use them.

my parent module pom

<!-- versions set by quarkus-bom, but they don't pass in, when changing quarkus version, update this from quarkus bom -->
<properties>
    <quarkus.version>1.0.0.CR1</quarkus.version>

    <agroal.version>1.7</agroal.version>
    <jakarta.enterprise.cdi-api.version>2.0.2</jakarta.enterprise.cdi-api.version>
    <jboss-jaxrs-api_2.1_spec.version>2.0.1.Final</jboss-jaxrs-api_2.1_spec.version>
    <jboss-logging.version>3.3.2.Final</jboss-logging.version>
    <jboss-threads.version>3.0.0.Final</jboss-threads.version>
    <smallrye-config.version>1.3.9</smallrye-config.version>
    <wildfly-common.version>1.5.0.Final-format-001</wildfly-common.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-universe-bom</artifactId>
            <version>${quarkus.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

my pom

<dependencies>
    <dependency>
        <groupId>com.lmco.is3.cs</groupId>
        <artifactId>datatypes</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
            </exclusion>
        </exclusions>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.lmco.is3.cs</groupId>
        <artifactId>utils</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.lmco.is3.nc</groupId>
        <artifactId>netcentric-if</artifactId>
        <version>1.0-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <groupId>io.undertow</groupId>
                <artifactId>undertow-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.spec.javax.websocket</groupId>
                <artifactId>jboss-websocket-api_1.1_spec</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>

    <dependency>
        <groupId>io.agroal</groupId>
        <artifactId>agroal-api</artifactId>
        <version>${agroal.version}</version>
    </dependency>
    <dependency>
        <groupId>io.agroal</groupId>
        <artifactId>agroal-narayana</artifactId>
        <version>${agroal.version}</version>
    </dependency>
    <dependency>
        <groupId>io.agroal</groupId>
        <artifactId>agroal-pool</artifactId>
        <version>${agroal.version}</version>
    </dependency>
    <dependency>
        <groupId>io.smallrye</groupId>
        <artifactId>smallrye-config</artifactId>
        <version>${smallrye-config.version}</version>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-agroal</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-artemis-jms</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-hibernate-orm</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy-jsonb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>${jboss-logging.version}</version>
    </dependency>
    <dependency>
        <groupId>org.wildfly.common</groupId>
        <artifactId>wildfly-common</artifactId>
        <version>${wildfly-common.version}</version>
    </dependency>
    <dependency>
        <groupId>jakarta.enterprise</groupId>
        <artifactId>jakarta.enterprise.cdi-api</artifactId>
        <version>${jakarta.enterprise.cdi-api.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.ws.rs</groupId>
        <artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
        <version>${jboss-jaxrs-api_2.1_spec.version}</version>
    </dependency>

application.properties

# Configures the Artemis properties.
quarkus.artemis.url=tcp://mq:61616?type=CF
quarkus.artemis.username=artemis
quarkus.artemis.password=simetraehcapa

quarkus.datasource.url=jdbc:postgresql://db:5432/stsdb
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.username=appuser
quarkus.datasource.password=appuser

quarkus.resteasy.gzip.enabled=true
quarkus.resteasy.gzip.max-input=10M

quarkus.log.category."com.lmco.is3.nc.micro.clock".level=INFO
2
HI, did you follow this guide quarkus.io/guides/hibernate-orm to setup Hibernate with Quarkus? If yes, can you give us your pom.xml and your application.properties ? - loicmathieu
As @loicmathieu says, this should work. Please provide more information about your code so we can help - geoand
Any way to upload my pom.xml instead of pasting it as a comment? Literally the code is not different, but maybe I am missing some dependency? - George Turner
Please edit your question and add the pom.xml (dependency part is enought) and your application.properties in it - loicmathieu
I think I faced that, and I put @ApplicationScoped to the class to solve it... - Xendar

2 Answers

8
votes

I figured it out! Not real "intuitive", but I had not migrated over any Entity classes yet. All it took was to put one class in scope and everything started working. So much for simple prototyping. Maybe it should have warned "no entity classes found".

0
votes

Friend, I had the same problem. Here's what I did that worked for me, I hope to help you:

added on application.properties quarkus.hibernate-orm."db".packages = packages with their entities example:

quarkus.hibernate-orm."db".packages=br.com.application.base.models

in my repositories:

@ApplicationScoped
@ActivateRequestContext
public class HeaderRepository {

    @PersistenceUnit("db")
     EntityManager entityManager;

I hope to help you following documentation: https://quarkus.io/guides/hibernate-orm

thanks