Average Hibernate / SQL of a table with multiple relationships

0

I have the following tables

TABLE1
id
value table2

TABLE2
id
table3

TABLE3
id

And with that, I would like to average TABLE 1, with WHERE in the TABLE 3 parameters with Hibernate / persistence, where my tables are objects.

It would look like this: SELECT AVG (value) FROM table1 WHERE table1.table2.table3.id = N?

    
asked by anonymous 01.11.2017 / 18:33

1 answer

1

Considering that:

  • Tables are correctly mapped into classes;

  • The classes are called, respectively, Tabela1 , Tabela2 and Tabela3 ;

  • The attributes of the classes are called tabela2 and tabela3 :

So you can do:

select avg(t.valor) from Tabela1 t where t.tabela2.tabela3.id = {valor}
    
01.11.2017 / 19:18