question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EntityManager in not injected when using devmode with gradle

See original GitHub issue

Describe the bug I’m using JPA + Hibernate without Panache. application.properties seems to be configured correctly. Beans injecting annotations are set. However EntityManager instance is not injected.

Expected behavior EntityManager instance is instantiated by Quarkus (Arc) and injected.

Actual behavior EntityManager instance is null.

To Reproduce Steps to reproduce the behavior:

  1. git clone git@github.com:4ntoine/NotesServerApp.git
  2. git checkout issue-5-quarkus
  3. ./gradlew :app-quarkus:quarkusDev
  4. navigate to “localhost:8080/hello” and make sure you can see stacktrace NPE’’

Configuration

quarkus.datasource.url = jdbc:h2:mem:notes
quarkus.datasource.driver = org.h2.Driver

# drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation=drop-and-create

Screenshots (If applicable, add screenshots to help explain your problem.) Снимок экрана 2019-11-15 в 0 05 26

Environment (please complete the following information):

  • Output of uname -a or ver:

Darwin MBP-Anton.local 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64

  • Output of java -version:
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.0.0CR1

Additional context CDI configuration:

package name.antonsmirnov.notes

import name.antonsmirnov.notes.gateway.JpaGateway
import name.antonsmirnov.notes.gateway.mapper.MapperImpl
import name.antonsmirnov.notes.usecase.*
import javax.enterprise.inject.Produces
import javax.inject.Inject
import javax.persistence.EntityManager

class QuarkusEntityManagerFactory {
    @Inject
    lateinit var entityManager: EntityManager // will be injected by Quarkus (but is not!)
}

class Configuration {
    val mapper = MapperImpl()
    val gateway = JpaGateway(QuarkusEntityManagerFactory().entityManager, mapper)
    val addNote: AddNote = AddNoteImpl(gateway)
    val listNotes: ListNotes = ListNotesImpl(gateway)

    @Produces
    fun getAddNoteUseCase(): AddNote = addNote

    @Produces
    fun getListNotesUseCase(): ListNotes = listNotes
}

dependencies configuration (Gradle + Kotlin DSL):

...
dependencies {
    implementation(project(":app-impl"))
    implementation(project(":infra-gateway-jpa"))
    implementation(project(":infra-rest-jax-rs")) {
        // provided by Quarkus or it's transitive dependencies
        exclude("javax.ws.rs:javax.ws.rs-api:2.0")
        exclude("javax.enterprise:cdi-api:2.0.SP1")
    }

    implementation("io.quarkus:quarkus-kotlin")
    implementation("io.quarkus:quarkus-resteasy-jsonb")
    implementation("io.quarkus:quarkus-jdbc-h2")
    implementation("io.quarkus:quarkus-hibernate-orm")
    implementation(enforcedPlatform("io.quarkus:quarkus-bom:1.0.0.CR1"))
    implementation("io.quarkus:quarkus-resteasy")
}
...

Does it look like correct CDI configuration? Should entityManager be injected by Quarkus before it’s entityManager accessed?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:25 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
SR-Lut3t1umcommented, Mar 14, 2020

@SR-Lut3t1um sure, that might not be the easiest to work with but still a reproducer. Thanks!

Here it is, I hope it’s good enough to work with.: https://gitlab.informatik.uni-bremen.de/tobias5/aut0m4t0n

2reactions
RotBoltcommented, Feb 12, 2020

I am taking up this issue. If its fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Hibernate ORM and JPA - Quarkus
This will inject the EntityManager of the default persistence unit. Injecting the EntityManager of a named persistence unit ( users in our example)...
Read more >
Failed to build quarkus application: Unsatisfied dependency ...
I'm trying to port a small corporate (multi module) RESTEasy JAX-RS application to Quarkus, but I'm hitting the error below. There a are...
Read more >
Home of Quarkus Cheat-Sheet - GitHub Pages
Also, you can start continuous testing and not dev mode by running mvn quarkus:test . ... EntityManager You can inject EntityManager in your...
Read more >
Developing Custom Gradle Types
Configuration using properties; DSL support and extensibility; Service injection; Creating objects explicitly; Collection types.
Read more >
Relational database connections with JDBC - Open Liberty
With Maven, you can use the copyDependencies element for the Open Liberty ... The Open Liberty Gradle plug-in does not directly support configuring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found