Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panache doesn't support method reference #41967

Open
DavideD opened this issue Jul 18, 2024 · 5 comments
Open

Panache doesn't support method reference #41967

DavideD opened this issue Jul 18, 2024 · 5 comments
Labels
area/panache kind/bug Something isn't working

Comments

@DavideD
Copy link
Contributor

DavideD commented Jul 18, 2024

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
@DavideD DavideD added the kind/bug Something isn't working label Jul 18, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 18, 2024

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

@FroMage
Copy link
Member

FroMage commented Jul 18, 2024

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
Copy link
Contributor Author

DavideD commented Jul 18, 2024

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

Thanks.

@FroMage
Copy link
Member

FroMage commented Jul 19, 2024

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
Copy link
Contributor Author

DavideD commented Jul 19, 2024

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.

@DavideD DavideD changed the title Panache deleteAll doesn't recognize the entity Panache doesn't support method reference Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants