After upgrading Hibernate from 3.2.4 to 4.1.7 we are facing some unneeded joins that are, in some cases, compromising performance. Let's show an example:
Let's say we have the following bidirectional one-to-many relationship : A (1)----->(*) B
Whenever we write an hql like this, hibernate makes two joins with the same entities (note that the HQL has a.b in projection)
- HQL
- select a.b from A a where a.b.name = 'entity_B'
- SQL result
select b1_.id as id1_, b1_.name as name1_ from A a0_inner join B b1_ on a0_.b_id=b1_.id cross join B b2_ <----------- unneeded join where a0_.b_id=b2_.id <----------- unneeded join and b2_.name='entity_B'
Hibernate 3.2.4 It generate the SQL as expected (note that the HQL has a.b.id in projection)
- HQL
- select a.b from A a where a.b.name = 'entity_B'
- SQL result
select b1_.id as id0_, b1_.name as name0_ from A a0_ inner join B b1_ on a0_.b_id=b1_.id where b1_.name='entity_B'
Its look like the problem is happening with the join, locate after the where, which is causing the colateral effect on the sql generator. It is not a critical bug it may impact in performance. Hope you fix this in next releases to make hibernate better than it is already is.
Thanks in advance
|