Hi,
We are trying to migrate Hibernate from version 3.2.4 to 4.1.7 and we are facing some issues due to the way HQL is transformed to SQL. It happens whenever developers decide to mix explicit with implicit joins (we know it is not a good practice to mix these two strategies, but we have a whole ERP develop this way :-( ).
Let me show an example:
Code:
from A a
left join fetch a.b b_alias
where a.b.name = :param
For the above HQL, hibernate 3.2.4 generates the following SQL:
Code:
select
a0_.id as id4_0_,
b1_.id as id5_1_,
a0_.b_id as b3_4_0_,
a0_.name as name4_0_,
b1_.name as name5_1_
from
A a0_
left join
B b1_
on a0_.b_id=b1_.id
where
b1_.name='entity_B'
It is ease to note that this hibernate's version actually tries to infers that the explicit join (i.e. left join fetch a.b b_alias) is the "same" that implicit one (i.e. a.b.name). Although we think it was an incorrect strategy to follow (once we have two different joins -- one left join and one inner join -- and hibernate merged it into only one left join), we could not change this hibernate behavior. Moreover, I don't think our developers have ever thought it would be changed some day.
In other way, if you run the same HQL in Hibernate 4.1.7, you will see that it is generating a completely different SQL.
Code:
Select
a0_.id as id0_0_,
b1_.id as id1_1_,
a0_.b_id as b3_0_0_,
a0_.name as name0_0_,
b1_.name as name1_1_
from
A a0_
left join
B b1_
on a0_.b_id=b1_.id
cross join
B b2_
where
a0_.b_id=b2_.id
and b2_.name='entity_B'
In this case the new version of hibernate is trying to infer nothing. Once developer have added two joins (one for the explicit join and another for the implicit join), as expected, hibernate generates two joins. Although we think this solution is more correct than the one provided in Hibernate 3.2.4, it is making our migration extremely painful (to not say nonviable).
So the question is: is there any configuration or change we could do to make the the query interpreter to behave like the legacy Hibernate 3.2.4? or the only way will be to review and "rewrite" every query in the system? We have also thought to make a "hack" to intercept the HQL and parse it in order to keep our current behavior. What do you think about this solution? There exists a simple way to do this?
Any help will be appreciated
Thanks in advance