question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hibernate Panache sorting not working with Named Query

See original GitHub issue

Describe the bug

Sorting not working with Named Query

@Entity
@NamedQueries({
        @NamedQuery(name = "countFruit",
                query = "FROM Fruit")
})
public class Fruit extends PanacheEntity {

    @Column(length = 40, unique = true)
    public String name;

    public static List<Fruit> listSortedFruitsByNamedQuery() {
        return list("#countFruit", Sort.by("name").ascending(), new HashMap<>()); // Not sorting
    }

    public static List<Fruit> listSortedFruits() {
        return list("FROM Fruit", Sort.by("name").ascending(), new HashMap<>()); //Sorting is done
    }

}

Expected behavior

find, list and stream functions should support sorting for named queries also.

Actual behavior

No errors, but the result list is not sorted if named query is used

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

openjdk version “11.0.11”

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.3.0.FINAL

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

Apache Maven 3.6.3

Additional information

Possible related issue: https://github.com/quarkusio/quarkus/issues/20758

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
yrodierecommented, Dec 13, 2021

Maybe we should add in the documentation that sorting should be made manyally with a named query

Or even better, we should throw an exception instead of silently ignoring when someone tries to sort and we cannot apply the sort.

1reaction
loicmathieucommented, Dec 16, 2021

OK then, I’ll implement an IllegalArgumentException when using named query and sort

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simplified Hibernate ORM with Panache - Quarkus
Named queries can only be defined inside your JPA entity classes (being the Panache entity class, or the repository parameterized type), or on...
Read more >
Named query for entity that does not associate with a specific ...
In the project I'm working on, it's around 5 JOIN tables to retrieve the information I'm looking for. table_b is purely a mapping...
Read more >
Sorting with Hibernate - Baeldung
The default sort order direction is ascending. This is why the order condition, asc, is not included in the generated SQL query. 2.1....
Read more >
Data Persistence with Quarkus and Hibernate Panache
So, you should have the following dependencies in your project. <dependencyManagement> <dependencies> <dependency> <groupId>io.quarkus</groupId> ...
Read more >
A Qute Way to Visualise Data with Panache - Antonio's Blog
One of these famous frameworks is Hibernate which implements the JPA specification. Hibernate makes mapping and querying Java objects easy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found