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

Missing support for auto-generated count methods in one-to-many relationships based on child entity attributes in Spring Repository #44026

Closed
aureamunoz opened this issue Oct 22, 2024 · 5 comments · Fixed by #44233
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Milestone

Comments

@aureamunoz
Copy link
Member

Describe the bug

Quarkus is not automatically generating a method to count entities in a one-to-many relationship where the parent entity has a child entity with a specific attribute, without needing to provide a custom JPQL query.

Expected behavior

Spring Data JPA is capable of automatically generating a method to count entities in a one-to-many relationship where the parent entity has a child entity with a specific attribute, without needing to provide a custom JPQL query. You can define the method signature in the repository interface, and Spring Data JPA will create the query for you based on the method name.

Assuming you have a Parent entity with a List relationship, and the Child entity has a name attribute, here's how you could define the method:
Repository Interface:

public interface ParentRepository extends JpaRepository<Parent, Long> {
    long countByChildren_Nombre(String nombre);
}

This method should count Parent entities that have children where the child's nombre matches the given value.

Actual behavior

The method is generated but the he following error is thrown when called:

Suppressed: org.hibernate.query.PathException: Plural path 'at.atc.database.entities.Parent(1).children' refers to a collection and so element attribute 'name' may not be referenced directly (use element() function)

How to Reproduce?

Here updated reproducer:
reproducerJPAListPropertyExpression.zip

Just run mvn clean test and the test will fail
Or start the application with mvn clean compile quarkus:dev and call the endpoint http://localhost:41000/test/rest/parents/1

Output of uname -a or ver

Darwin amunozhe-mac 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21.0.3" 2024-04-16 LTS

Quarkus version or git rev

No response

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

No response

Additional information

No response

@aureamunoz aureamunoz added the kind/bug Something isn't working label Oct 22, 2024
@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label Oct 22, 2024
Copy link

quarkus-bot bot commented Oct 22, 2024

/cc @geoand (spring)

@aureamunoz
Copy link
Member Author

I'm on it @geoand. I've just created the issue for traceability.

cc @Michael-AT-Corporation

@geoand
Copy link
Contributor

geoand commented Oct 22, 2024

🙏

@gsmet
Copy link
Member

gsmet commented Nov 16, 2024

@aureamunoz in the end, was this one fixed?

@aureamunoz
Copy link
Member Author

Not yet. I'm still on it.

@quarkus-bot quarkus-bot bot added this to the 3.18 - main milestone Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants