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

Unable to perform a count operation on a named query #10319

Closed
fwgreen opened this issue Jun 27, 2020 · 9 comments · Fixed by #10455
Closed

Unable to perform a count operation on a named query #10319

fwgreen opened this issue Jun 27, 2020 · 9 comments · Fixed by #10455
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@fwgreen
Copy link

fwgreen commented Jun 27, 2020

This is probably less of a bug and more of a gap in my Hibernate/HQL knowledge. Basically my named query works with find but throws when I add count.

@Entity
@DiscriminatorValue("RN")
@NamedQuery(name="Nurse.available", 
            query="select n from Nurse n, Availability av where n.id = av.teamMember and av.onShift = true")
public class Nurse extends TeamMember {

    public static List<Nurse> onShift() {
        return find("#Nurse.available"); //works fine
    }

    public static long onShiftCount() {
        return find("#Nurse.available").count(); //throws exception
    }
}
org.jboss.resteasy.spi.UnhandledException: io.quarkus.panache.common.exception.PanacheQueryException: Unable to perform a count operation on a named query

The immediate workaround to use the query directly:

public static long onShiftCount() {
    return find("select n from Nurse n, Availability av where n.id = av.teamMember and av.onShift = true").count(); //this works!
}

Java 14
Quarkus 1.5.2

@fwgreen fwgreen added the kind/bug Something isn't working label Jun 27, 2020
@geoand
Copy link
Contributor

geoand commented Jun 28, 2020

cc @Sanne

@Sanne
Copy link
Member

Sanne commented Jun 28, 2020

I'll pass it to @FroMage :)

@FroMage
Copy link
Member

FroMage commented Jun 30, 2020

Yeah, the way we handle them is not by replacing the body of the method with the text of the query, but just passing it on to ORM, which doesn't support that.

Now, granted, in some cases we could actually make this work by using the named query text itself and applying the same transformation we do for regular queries to be able to count them.

@loicmathieu since you did the named queries, would you be interested in looking at this?

@loicmathieu
Copy link
Contributor

I can have a look.

Another implementation would be to offer the user a way to pass it's own countQuery, but this will defeat the simplicity of Panache regarding the count() method.

@GithubSre
Copy link

io.quarkus.panache.common.exception.PanacheQueryException: The named query must be defined on your JPA entity or one of its super classes. Does anyone know how to fix this?

@GithubSre
Copy link

if yes please let me know.

@loicmathieu
Copy link
Contributor

@GithubSre this means that the named query annotation was not found.

This issue is closed, please ask on stackoverfow or Zulip for help or open a new issue with a reproducer.

@GithubSre
Copy link

thanks @loicmathieu

@GithubSre
Copy link

this helped solve the problem.
Thanks @loicmathieu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants