quarkusio / quarkus

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

Panache doesn't support method reference #41967

Open DavideD opened 2 months ago

DavideD commented 2 months ago

Describe the bug

You can see this error by updating the hibernate-reactive-panche-quickstart.

Replace the FruitResource#delete with:

   @DELETE
   public Uni<Response> deleteAll() {
       return Panache.withTransaction(Fruit::deleteAll)
               .map(deleted -> Response.ok("Number of fruits deleted: " + deleted).build());
   }

Calling the rest point via HTTP will cause:

➜  hibernate-reactive-panache-quickstart git:(main) ✗ http DELETE localhost:8080/fruits
HTTP/1.1 500 Internal Server Error
Content-Type: application/json;charset=UTF-8
content-length: 189

{
    "code": 500,
    "error": "This method is normally automatically overridden in subclasses: did you forget to annotate your entity with @Entity?",
    "exceptionType": "java.lang.IllegalStateException"
}

Expected behavior

If I change the method to:

    @DELETE
    public Uni<Response> deleteAll() {
        return Panache
                .withTransaction( () -> Fruit.deleteAll() )
                .map( deleted -> Response.ok( "Number of fruits deleted: " + deleted ).build() );
    }

everything works as expected:

➜  hibernate-reactive-panache-quickstart git:(main) ✗ http DELETE localhost:8080/fruits
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
content-length: 27

Number of fruits deleted: 3
quarkus-bot[bot] commented 2 months ago

/cc @FroMage (panache), @loicmathieu (panache)

FroMage commented 2 months ago

It's the Fruit::deleteAll that is the problem, I bet. It will work if you do () -> Fruit.deleteAll().

Besides transforming these lambdas with build transformers, I'm not sure how to fix this.

DavideD commented 2 months ago

Yes, that solved the issue. Annoying, but if there's nothing we can do, I will just close it.

Thanks.

FroMage commented 2 months ago

There might be ways to solve those, I'd have to look at the bytecode. But I am not sure it's worth spending that time, as the error is pretty rare. I think you're the first to report it.

DavideD commented 2 months ago

It's OK, it's not critical. And, It's relatively easy to find workarounds. If you don't have time maybe somewhere else will.

It's just annoying not to be able to use method reference. Maybe a note on the website or in the documentation can be helpful.