Blazebit / blaze-persistence

Rich Criteria API for JPA providers
https://persistence.blazebit.com
Apache License 2.0
727 stars 85 forks source link

Add a Quarkus integration to allow running in the JVM and Native mode #817

Closed soberich closed 4 years ago

soberich commented 5 years ago

Description

There is a repo with reproducer.

Actual behavior

dumps NPE short stacktrace to stdout

Caused by: java.lang.NullPointerException
    at com.blazebit.persistence.integration.hibernate.Hibernate53Integrator.integrate(Hibernate53Integrator.java:58)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:275)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
    at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:64)
    ... 13 more

Steps to reproduce

This commit https://github.com/soberich/marvel/commit/66e29c94071b75345b132b453c092a12575e8b0f

on this branch bigfix/blaze-fails-to-integate-with-hibernate shows how I added blaze to try it out with quarkus.

git clone -b bigfix/blaze-fails-to-integate-with-hibernate git@github.com:soberich/marvel.git;
cd marvel;
./gradlew quarkusDev -S

On startup there would be an exception.

Environment

Version: [1.3.2,1.4.1) JPA-Provider: Hibernate 5.4 DBMS: H2
Application Server: Netty/Undertow

Mobe91 commented 5 years ago

@soberich I am receiving the following error when I run your project with gradlew.bat quarkusDev -S on Windows:

Caused by: org.gradle.internal.resolve.ArtifactNotFoundException: Could not find guice-no_aop.jar (com.google.inject:guice:4.2.0).
Searched in the following locations:
    file:/C:/Users/<User>.m2/repository/com/google/inject/guice/4.2.0/guice-4.2.0-no_aop.jar

The directory only contains guice-4.2.0.jar.

soberich commented 5 years ago

@Mobe91 This is funny because makes no sense for me. What does it have to do with Guice? this project have nothing to do with Guice. I see exception pointing to internals of Gradle which is even more confusing, and also, I rarely use local artefacts repos. Project lists a lot of repositories to lookup for dependencies, so it can get them in as many places as possible as it is a playground. Please try to check these:

  1. Are you sure you are in the right folder?
  2. Are you using firewall, proxy which can limit web-access?
  3. Are there any Gradle specific company-wise or machine wise properties applied (e.g. in ~/.gradle/...properties
  4. Are you sure you are not supplying implicitly some flags like --offline or something with similar semantics to make gradle only resolve in restricted manner.

Last two are most viable candidates. Hope I am already too late and you have figured out what was wrong. Please, let me know @Mobe91 thank you.

EDIT: As you see above I mentioned your comment in commit where I removed any bounds from mavenLocal() which is just to try, though I am 100% sure it is not the case, but just to take some action on your comment.

soberich commented 5 years ago

Below I provide as full stacktrace as I could get. The error in question, unfortunately prints to stdout in quite, so it is still trimmed no matter what.

2019-07-17 00:30:50,323 DEBUG [io.qua.arc] (main) ArC DI container shut down
2019-07-17 00:30:50,323 ERROR [io.qua.dev.DevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:142)
        at io.quarkus.runtime.Application.start(Application.java:84)
        at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:121)
        at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:171)
        at io.quarkus.dev.DevModeMain.main(DevModeMain.java:89)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.persistenceException(FastBootEntityManagerFactoryBuilder.java:106)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:66)
        at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:54)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
        at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:109)
        at io.quarkus.hibernate.orm.runtime.JPAConfig.startAll(JPAConfig.java:57)
        at io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder.startAllPersistenceUnits(HibernateOrmRecorder.java:77)
        at io.quarkus.deployment.steps.HibernateOrmProcessor$startPersistenceUnits22.deploy_0(HibernateOrmProcessor$startPersistenceUnits22.zig:51)
        at io.quarkus.deployment.steps.HibernateOrmProcessor$startPersistenceUnits22.deploy(HibernateOrmProcessor$startPersistenceUnits22.zig:70)
        at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:82)
        ... 4 more
Caused by: java.lang.NullPointerException
        at com.blazebit.persistence.integration.hibernate.Hibernate53Integrator.integrate(Hibernate53Integrator.java:58)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:275)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
        at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:64)
        ... 13 more
jwgmeligmeyling commented 5 years ago

An NPE at line 58 indicates that the Database service binding is not available. Missing services indicate a classpath problem. Java's Service Provider mechanism is described in for example this blogpost. The services are usually registered through resource files in META-INF/services/. Recently I stumbled upon a very similar issue myself, when I was creating a WildFly module for Blaze-Persist (documented on Slack). I don't know how Quarkus works, but I suppose it creates some sort of special classpath where services from libraries are hidden, or the Service Provider API is not available at all. From a simple Google search I cannot easily find examples of the Service Provider API within Quarkus.

One thing that you might want to try is to copy the contents of the META-INF/services folder of the jar dependencies to your applications META-INF/services folder.

This should at least contain the files:

com.blazebit.persistence.integration.hibernate.base.HibernateAccess
com.blazebit.persistence.spi.EntityManagerFactoryIntegrator
org.hibernate.boot.spi.MetadataContributor
org.hibernate.integrator.spi.Integrator
org.hibernate.persister.spi.PersisterClassResolver
org.hibernate.service.spi.ServiceContributor

(these are the ones from blaze-persistence-integration-hibernate-5.3:1.3.2, but the other jars probably have services too)

jwgmeligmeyling commented 5 years ago

@soberich were my remarks any useful?

soberich commented 5 years ago

@JWGmeligMeyling yes. It should be something about writing extension https://quarkus.io/guides/extension-authors-guide But does library considers that kind of support? There are some frameworks like Micronaut, Quarkus etc, which would be really nice to have.

beikov commented 5 years ago

At this time, I do not anticipate to work on this as there are other features I consider more important. At some point I will look into this, but the hibernate integration and entity views relies heavily on reflection, so I guess it will be a lot of work to get Blaze-Persistence fully running with Quarkus. If anyone wants to work on this, I can help with explaining what is necessary or provide guidance.

soberich commented 5 years ago

@beikov @JWGmeligMeyling I have raised a feature-request there as you see. Let's leave this open.

Mobe91 commented 4 years ago

In case anyone stumbles over the issues I had with running the demo project: This is a gradle issue.

You need to delete the parent directory of the guice dependency in your local maven repository, otherwise gradle won't attempt to download the no_aop version of the dependency, i.e. delete ~/.m2/repository/com/google/inject/guice/4.2.0 and then it should work.

And you need to run it with JDK8.