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

NamedQuery inside repository #40987

Closed
akastyka opened this issue Jun 5, 2024 · 7 comments · Fixed by #41053
Closed

NamedQuery inside repository #40987

akastyka opened this issue Jun 5, 2024 · 7 comments · Fixed by #41053
Labels
area/panache kind/bug Something isn't working
Milestone

Comments

@akastyka
Copy link

akastyka commented Jun 5, 2024

Describe the bug

According to the documentation it is possible to define a @NamedQuery at entity's repository

Named queries can only be defined inside your Jakarta Persistence entity classes (being the Panache entity class, or the repository parameterized type), or on one of its super classes.

(link https://quarkus.io/guides/hibernate-orm-panache#named-queries)

However it fails with :

io.quarkus.panache.common.exception.PanacheQueryException: The named query 'Test.update' must be defined on your JPA entity or one of its super classes

Expected behavior

@NamedQuery on top of repositories works in same way as at Entities

Actual behavior

@NamedQuery on top of repositories fails with

o.quarkus.panache.common.exception.PanacheQueryException: The named query 'Test.update' must be defined on your JPA entity or one of its super classes

How to Reproduce?

Define @Entity, define its repository which implements PanacheRepositoryBase<_Entity_, UUID>, define @NamedQuery on top of repository.

Output of uname -a or ver

No response

Output of java -version

openjdk version "21.0.2" 2024-01-16 LTS

Quarkus version or git rev

3.11.0

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

Gradle 8.8

Additional information

No response

@akastyka akastyka added the kind/bug Something isn't working label Jun 5, 2024
@geoand geoand added area/hibernate-orm Hibernate ORM and removed triage/needs-triage labels Jun 6, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 6, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere yrodiere added area/panache and removed area/hibernate-orm Hibernate ORM labels Jun 6, 2024
@yrodiere
Copy link
Member

yrodiere commented Jun 6, 2024

I think this is just a documentation problem, right @FroMage?
I don't know how defining named queries on repositories would work, as those classes are not technically part of the persistence unit as far as Hibernate ORM is concerned.

@FroMage
Copy link
Member

FroMage commented Jun 7, 2024

Looking at the processor code, it appears that indeed it's a documentation issue, we only look at named queries on the entities and their hierarchy.

@FroMage
Copy link
Member

FroMage commented Jun 7, 2024

I think, perhaps, that "being the Panache entity class, or the repository parameterized type" means "the panache entity, or the type argument to the repository" but that's not clear at all, I'll delete that part.

FroMage added a commit to FroMage/quarkus that referenced this issue Jun 7, 2024
@FroMage
Copy link
Member

FroMage commented Jun 7, 2024

PR done #41053

@akastyka
Copy link
Author

akastyka commented Jun 7, 2024

Spring provides a possibility to specify queries inside repositories:

Using @Query
Using named queries to declare queries for entities is a valid approach and works fine for a small number of queries. As the queries themselves are tied to the Java method that runs them, you can actually bind them directly by using the Spring Data JPA @Query annotation rather than annotating them to the domain class. This frees the domain class from persistence specific information and co-locates the query to the repository interface.

Queries annotated to the query method take precedence over queries defined using @NamedQuery or named queries declared in orm.xml.

Would be good to have something similar in quarkus

@quarkus-bot quarkus-bot bot added this to the 3.12 - main milestone Jun 10, 2024
@FroMage
Copy link
Member

FroMage commented Jun 10, 2024

We are working on type-safe queries for Hibernate in Quarkus.

@gsmet gsmet modified the milestones: 3.12 - main, 3.11.2 Jun 10, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jun 10, 2024
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Jul 31, 2024
@gsmet gsmet modified the milestones: 3.11.2, 3.8.6 Aug 7, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 7, 2024
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 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

Successfully merging a pull request may close this issue.

5 participants