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.

Fetch join with pagination fails to append LIMIT in the generated HQL

See original GitHub issue

Hi,

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:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
svnsivacommented, Mar 13, 2018

@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.

1reaction
pshingavicommented, Nov 20, 2016

@darrachequesne Yes, I got this working with the v3.0 version. Thanks a ton for the fix !

Read more comments on GitHub >

github_iconTop 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 >

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