Started with Vaadin, I need help

Hello to all,

I just started learning Vaadin, and I have question how to bind SQL result to grid element without beans.

For example, I have SQL:
SELECT users.id, users.firstname, users.lastname, city.name, city.postal_code, state.name, country.name

SQL query is using more than one table.

How to bind this multitable query to grid element in Vaadin.

Thanks

Hi Luka,

Have you considered JPA’s @SqlResultSetMapping? Simply put, you define a POJO with fields for the columns of your result set, let JPA map the result to that POJO and then pass the POJO to Grid.

Another approach if you are using JPA is to use JPQL’s new keyword to call the constructor of your POJO direcly in JPQL. So your query will look like SELECT new MyResultPOJO(users.id, users.firstname,city.name,...) FROM ....

I hope this suffices for your use case. Please let me know if I might be of further help.

References:

https://docs.oracle.com/javaee/7/api/javax/persistence/SqlResultSetMapping.html

https://www.thoughts-on-java.org/result-set-mapping-constructor-result-mappings/

https://vladmihalcea.com/the-best-way-to-map-a-projection-query-to-a-dto-with-jpa-and-hibernate/