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

PanacheRepositoryResource fails on POST when the resource's path includes a @PathParam #35167

Closed
CYBERSHOU opened this issue Aug 2, 2023 · 7 comments
Labels
area/panache kind/bug Something isn't working

Comments

@CYBERSHOU
Copy link

CYBERSHOU commented Aug 2, 2023

Describe the bug

I'm using the PanacheRepositoryResource interface to create the Jax Resources.
The only difference from what works is the use of a path parameter, like "/project/{projectId}/".

All my POST requests end up with 500 errors saying "Failed to add an entity" and further down the stacktrace it says
"Discovery failed for method com.envisage.gene.rest.project.dependent.TargetResourceJaxRs_597046d94bad44a89428c15444fc02a72e8750c2.get: RESTEASY012060: Not enough URI parameters: expecting 2 but only found 1".

Bearing in mind that the endpoint I'm trying to hit is something like:
http://localhost:8080/api/project/{projectId}/target

After a lot of tinkering around, I can only assume the error must be something with Panache itself.
Unless I have missed something.

Expected behavior

Actual behavior

How to Reproduce?

No response

Output of uname -a or ver

Linux 5.15.0-78-generic 20.04.1-Ubuntu

Output of java -version

openjdk version "11.0.20" 2023-07-18 LTS OpenJDK Runtime Environment Corretto-11.0.20.8.1 (build 11.0.20+8-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.20.8.1 (build 11.0.20+8-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.2.2.Final

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

Apache Maven 3.9.3 (21122926829f1ead511c958d89bd2f672198ae9f)

Additional information

The stacktrace of the error
image

@CYBERSHOU CYBERSHOU added the kind/bug Something isn't working label Aug 2, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 2, 2023

/cc @FroMage (panache), @Sgitario (rest-data-panache), @loicmathieu (panache)

@Sgitario
Copy link
Contributor

Sgitario commented Aug 2, 2023

This error seems to be related to the generation of the links. As a workaround, you can try with disabling hal:

@ResourceProperties(hal = false)
public interface CollectionsResource extends PanacheRepositoryResource<CollectionsRepository, Collection, String> {
}

About the issue, can you share your resource class to reproduce and better troubleshoot what the root cause is? Thanks!

@CYBERSHOU
Copy link
Author

This error seems to be related to the generation of the links. As a workaround, you can try with disabling hal:

@ResourceProperties(hal = false)
public interface CollectionsResource extends PanacheRepositoryResource<CollectionsRepository, Collection, String> {
}

Thank you, but the issue remains. My ugly workaround right now is extending the path of the endpoint with "/add" by using a default method.

About the issue, can you share your resource class to reproduce and better troubleshoot what the root cause is? Thanks!

Yes! I will add an example.

@CYBERSHOU
Copy link
Author

Here is a entity I created to test the issue.

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;

@Entity
public class Test {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "test_seq")
    @SequenceGenerator(name = "test_seq", sequenceName = "test_sequence")
    private Long id;

    private String description;

    public Test() {}

    public Test(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}

The entity's repository is the standard:

import io.quarkus.hibernate.orm.panache.PanacheRepository;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class TestRepository implements PanacheRepository<Test> {
}

And the resource:

import io.quarkus.hibernate.orm.rest.data.panache.PanacheRepositoryResource;
import io.quarkus.rest.data.panache.ResourceProperties;

@ResourceProperties(hal = false, path = "api/project/{projectId}/test")
public interface TestResource extends PanacheRepositoryResource<TestRepository, Test, Long> {
}

I was able to reproduce the issue with this.

image

@Sgitario
Copy link
Contributor

Sgitario commented Aug 3, 2023

So, you're trying to use it as a sub-resource of a top parent resource. There is an existing feature request to support this use case: #28450
Closing as duplicated.

@Sgitario Sgitario closed this as completed Aug 3, 2023
Sgitario added a commit to Sgitario/quarkus that referenced this issue Aug 3, 2023
This is related to quarkusio#35167.
Even though HAL is disabled by default, it's still used to generate unexpected links and to set the location.
Sgitario added a commit to Sgitario/quarkus that referenced this issue Aug 3, 2023
This is related to quarkusio#35167.
Even though HAL is disabled by default, it's still used to generate unexpected links and to set the location.
@Sgitario
Copy link
Contributor

Sgitario commented Aug 3, 2023

This error seems to be related to the generation of the links. As a workaround, you can try with disabling hal:

@ResourceProperties(hal = false)
public interface CollectionsResource extends PanacheRepositoryResource<CollectionsRepository, Collection, String> {
}

Thank you, but the issue remains. My ugly workaround right now is extending the path of the endpoint with "/add" by using a default method.

About disabling HAL, this was actually a bug that should be fixed in #35181. So, after merging this pull request, your issue will be gone.

Sgitario added a commit to Sgitario/quarkus that referenced this issue Aug 4, 2023
This is related to quarkusio#35167.
Even though HAL is disabled by default, it's still used to generate unexpected links and to set the location.
Sgitario added a commit to Sgitario/quarkus that referenced this issue Aug 4, 2023
This is related to quarkusio#35167.
Even though HAL is disabled by default, it's still used to generate unexpected links and to set the location.
@CYBERSHOU
Copy link
Author

Thank you!

gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 9, 2023
This is related to quarkusio#35167.
Even though HAL is disabled by default, it's still used to generate unexpected links and to set the location.

(cherry picked from commit 362f03a)
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