quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.65k forks source link

Hibernate reactive panache quickstart with UUIDGenerator throws error in native mode #21217

Closed Lahres-Dev closed 3 days ago

Lahres-Dev commented 2 years ago

Describe the bug

Running a customized hibernate-reactive-panache-quickstart project in native mode throws Could not interpret id generator strategy [org.hibernate.id.UUIDGenerator] This looks similar to #1743

Expected behavior

Should work like in dev or jvm mode

Actual behavior

Does not run in native mode

How to Reproduce?

  1. Customize hibernate-reactive-panache-quickstart Fruit class from

    @Entity
    @Cacheable
    public class Fruit extends PanacheEntity {
    
    @Column(length = 40, unique = true)
    public String name;
    
    public Fruit() {
    }
    
    public Fruit(String name) {
        this.name = name;
    }
    

} to

@Entity
@Cacheable
public class Fruit extends PanacheEntityBase {

    @Id
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    @GeneratedValue(generator = "UUID")
    public UUID id;

    @Column(length = 40, unique = true)
    public String name;

    public Fruit() {
    }

    public Fruit(String name) {
        this.name = name;
    }
}
  1. Run project in native mode

Output of uname -a or ver

MINGW64_NT-10.0-19043 XXXX 1 3.1.7-340.x86_64 2021-03-26 22:17 UTC x86_64 Msys

Output of java -version

openjdk 11.0.11 2021-04-20 LTS OpenJDK Runtime Environment Corretto-11.0.11.9.1 (build 11.0.11+9-LTS) OpenJDK Server VM Corretto-11.0.11.9.1 (build 11.0.11+9-LTS, mixed mode, emulated-client)

GraalVM version (if different from Java)

GraalVM 21.2.0 Java 11 CE (from native container build)

Quarkus version or git rev

2.4.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: C:\Users\XXXX.m2\wrapper\dists\apache-maven-3.8.1-bin\2l5mhf2pq2clrde7f7qp1rdt5m\apache-maven-3.8.1 Java version: 11.0.11, vendor: Amazon.com Inc., runtime: C:\copybase\jdk11.0.11_9 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "x86", family: "windows"

Additional information

No response

quarkus-bot[bot] commented 2 years ago

/cc @DavideD, @FroMage, @Sanne, @gavinking, @loicmathieu

geoand commented 2 years ago

I was able to reproduce this.

What seems weird to me is that we have integration tests that use this same pattern and test native mode.

gsmet commented 2 years ago

/cc @DavideD

DavideD commented 2 years ago

Please, can you assign this to me?

geoand commented 2 years ago

Done

omar-zahid commented 2 years ago

@DavideD Any update on this issue? I'm getting similar error on native image. image

DavideD commented 2 years ago

Sorry, I haven't had time to look into this yet

HknLof commented 2 years ago

Running into the same Exception for 2.10.0.Final and gradle 7.4.2 this still occurs.

./gradlew --version


------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------

Build time:   2022-03-31 15:25:29 UTC
Revision:     540473b8118064efcc264694cbcaa4b677f61041

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.15 (Azul Systems, Inc. 11.0.15+10-LTS)
OS:           Mac OS X 12.1 x86_64

./gradlew quarkusInfo

> Task :platform-api:quarkusInfo
quarkusInfo is experimental, its options and output might change in future versions
Looking for the newly published extensions in registry.quarkus.io
Quarkus platform BOMs:
  io.quarkus.platform:quarkus-bom:pom:2.10.0.Final

Extensions from io.quarkus.platform:quarkus-bom:
  io.quarkus:quarkus-logging-json
  io.quarkus:quarkus-resteasy-reactive-jackson
  io.quarkus:quarkus-smallrye-health
  io.quarkus:quarkus-config-yaml
  io.quarkus:quarkus-hibernate-reactive
  io.quarkus:quarkus-smallrye-metrics
  io.quarkus:quarkus-kubernetes
  io.quarkus:quarkus-container-image-jib
  io.quarkus:quarkus-reactive-pg-client
  io.quarkus:quarkus-smallrye-openapi
  io.quarkus:quarkus-smallrye-reactive-messaging-kafka

Extensions from registry.quarkus.io:
  io.quarkiverse.hibernatetypes:quarkus-hibernate-types:0.2.0
philippegoncalves commented 2 years ago

Getting the same exception here running in native mode, any new on this issue ? Using 2.10.1.Final with gradle 7.4.2.

philippegoncalves commented 2 years ago

Same issue reproducible on latest version 2.11.2. Something strange is, sometimes the native compile produce a binary that does not throw this error at startup, but most of the time it will. Note that we have a multi module project with a complex architecture, but this should not impact the native build compilation.

philippegoncalves commented 2 years ago

I just realized that the issue is because of using command assemble instead of build when using gradle as the build tool. Our bad, maybe it is worth it to specify on the documentation to only use the build command, as it is known to run the test as well, but not when building in native mode. I believe people coming from other gradle projects will be tempted to use the assemble command. @HknLof are you using the build command or assemble ?

Lahres-Dev commented 2 years ago

When registering UUIDGenerator for reflection, everything works fine. I'm not sure if this is considered a workaround or is intended:

@RegisterForReflection(targets = UUIDGenerator.class)
class MyReflectionConfiguration {}

See also: https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection

philippegoncalves commented 2 years ago

Yes it works by using the annotation.

HknLof commented 2 years ago

@philippegoncalves Have not tried in a while, but we are using ./gradlew build. I will update Quarkus and gradlew versions and run the resulting image again. I will let you know about the outcome.

          ./gradlew build --info --no-daemon -x test \
                -Dquarkus.jib.platforms=linux/amd64,linux/arm64 \
                -Dquarkus.container-image.build=true \
                -Dquarkus.container-image.push=true \
                -Dquarkus.container-image.registry=ghcr.io \
                -Dquarkus.native.container-build=true \
                -Dquarkus.package.type=native \
                ...
philippegoncalves commented 2 years ago

On my side @HknLof I still need to add the @RegisterForReflection mentioned by @Lahres-Dev eventhough it is supposed to work wothout it based on https://github.com/quarkusio/quarkus/issues/1743

Sanne commented 2 years ago

Yes that's a good workaround. As mentioned we'll eventually rewrite the Hibernate Reactive extension to take such things into account, but we need to focus on Jakarta 10 + Hibernate ORM 6 first; so please use this workaround in the meantime.

guoxunbo commented 1 year ago

Hello. have the same exception in 2.13.3.final.

geoand commented 5 days ago

Is this still an issue with the latest versions of Quarkus?

DavideD commented 3 days ago

It seems to work fine with Quarkus 3.15.1

geoand commented 3 days ago

Thanks for checking