Fetch join with pagination fails to append LIMIT in the generated HQL
See original GitHub issueHi,
I have an entity
Order
{
@Id
@GeneratedValue
@Column(name="order_id")
private BigInteger orderId;
@OneToMany(mappedBy = "order")
private Set<OrderLine> orderLines;
}
and bi-directional mapping in entity
OrderLine
{
@Id
@Column(name="order_id")
@GeneratedValue(generator="gen")
@GenericGenerator(name="gen", strategy="foreign", parameters=@org.hibernate.annotations.Parameter(name="property", value="order"))
private BigInteger orderId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "order_id", updatable = false, insertable = false)
@JsonIgnore
private Order order;
}
My order repository extends the DataTablesRepository interface. When I had OneToOne mapping the results were fast and the HQL generated had LIMIT in the query. But with the above mapping LIMIT is missing in the query and it takes a long time to fetch all records and then do in memory mapping to return the paginated result.
It’s been more than 3 weeks I am trying to find a work around but not able to figure out how. Can you suggest how can I solve this issue.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Hibernate - HQL pagination - Stack Overflow
I have a PostgreSQL database. int elementsPerBlock = 10; int page = 2; //offset = 2*10 String sqlQuery = "FROM Messages AS msg...
Read more >Query pagination with JPA and Hibernate - Vlad Mihalcea
JOIN FETCH and pagination ... This is because Hibernate wants to fetch entities fully along with their collections as indicated by the JOIN...
Read more >Pagination with JPA and Hibernate - Thorben Janssen
You can, of course, use pagination with JPA and Hibernate. The easiest way to do that is to add the LIMIT and OFFSET...
Read more >Simplified Hibernate ORM with Panache - Quarkus
the list() method might be surprising at first. It takes fragments of HQL (JP-QL) queries and contextualizes the rest. That makes for very...
Read more >Guide to Pagination with Hibernate - HowToDoInJava
The HQL methods Query#setMaxResults() and Query#setFirstResult() are used to limit the number of results and control pagination.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pshingavi @darrachequesne I am facing the same problem. Can any of you provide the solution. I couldn’t find anything in the GitHub link available above.
@darrachequesne Yes, I got this working with the v3.0 version. Thanks a ton for the fix !