Hibernate version: 3.0.1
Name and version of the database you are using: Oracle 10g
If I use HQL and forget to use an alias on the joined class, then the sql generated adds an extra join with this table for any condition on it. If i have the HQL
select count(*) ,sum(movs.mtoOpe)
from ClassTotal actual left join actual.movimientos movs
where movs.fchOpe > :fchMax
group by actual.codEmp,actual.codCen
The generated query is OK. But, in my first attempt, I wrote
select count(*) ,sum(actual.movimientos.mtoOpe)
from ClassTotal actual left join actual.movimientos movs
where actual.movimientos.fchOpe > :fchMax
group by actual.codEmp,actual.codCen
And the generated query was:
select sum(movimiento2_.mto_ope) as col_2_0_, count(*) as col_3_0_
from total almsdomens0_ left outer join movements movimiento1_ on
almsdomens0_.cod_emp=movimiento1_.cod_emp and
movements movimiento2_, movements movimiento3_
where almsdomens0_.tip_mov='S' and
almsdomens0_.cod_emp=movimiento3_.cod_emp and
almsdomens0_.cod_emp=movimiento2_.cod_emp and
movimiento3_.fch_ope>?
group by almsdomens0_.cod_emp , almsdomens0_.cod_cen
(Note the movements after the join condition)
I dont know if it is a bug, and, anyway, the workaround is easy (to always use an alias) but this point made me spent a lots of hours and I think it would be useful for another person.
Regards.
|