I’m trying to implement a Vaadin application where some data is displayed in a grid. The user can filter the data displayed in the grid and paginate over it.
An example of this is the entity Sales which defines a ManyToOne(optional=true) relation to the entity Customers, as not all the sales require a customer assigned. I’m using a NamedEntityGraph from Sales to Customers in order to fetch customer name in the findAll(Specification) method to populate the grid. The fetch sql is executing a left join between sales table and customers table which is fine. However, the count query (required by vaadin pagination) is executing an inner join, which is not fine as it’s ignoring sales whithout customer assigned.
I don’t know how to force count method to use the EntityGraqh or even if this is possible. If no, please could you explain to me an alternative way for accomplishing this?.
The stack is using Spring Boot 3.0.5, Hibernate 6.1.7.Final and Vaadin 24.
Hi, this is a forum for Hibernate ORM questions. You seem to have a problem with some sort of Vaadin extension or Spring Data that try to generate a query for you.
Unless you have a problem with Hibernate ORM itself, please post your questions to the forums of the respective extension vendors, as nobody in this forum has an idea about what these tools are doing.
Thanks for your quick response and sorry if it’s not the proper forum for it. I’ve included information regarding the stack in order to provide some context for my question.
Please, let me reformulate my question. Basically, my question is if I’m able to execute a query generated with CriteriaBuilder, which is using a NamedEntityGraph, how can I execute a count query with the same criteria and entity graph whicch was applied to the fecth query?.
You don’t need an entity graph for a count query, because you are not fetching anything. Since Hibernate ORM 6.4 you can create a count query from an existing
CriteriaQuery: Hibernate ORM User Guide
Thank you very much for your response. I’ll try your suggestion. As we’re in an early phase, I don’t think there is any problem moving to Hibernate ORM 6.4.