Hibernate version:
3.2.1 and 3.2
I have a 1:n to 1:n relation, ie. Forest has many Trees has many Leafs.
I try to select all Trees having a leaf which name is test.
Code:
session.createCriteria(Tree.class).createCriteria("leafs").add(Restrictions.eq("name", "test")).list();
If I use XML mapping, I receive a proper query:
Code:
select this_.id as id1_1_, leaf1_.id as id0_0_, leaf1_.name as name0_0_, leaf1_.tree_id as tree3_0_0_
from tree this_ inner join leaf leaf1_ on this_.id=leaf1_.tree_id where leaf1_.name=?
but if I use annotation mapping, I get a very ugly join returning not even the correct values:
Code:
select this_.id as id2_3_, this_.forest_id as forest2_2_3_, leaf1_.id as id0_0_, leaf1_.tree_id as tree3_0_0_,
leaf1_.name as name0_0_, tree4_.id as id2_1_, tree4_.forest_id as forest2_2_1_, forest5_.id as id1_2_
from Tree
this_ inner join Leaf leaf1_ on this_.id=leaf1_.tree_id
left outer join Tree tree4_ on leaf1_.tree_id=tree4_.id
left outer join Forest forest5_ on tree4_.forest_id=forest5_.id where leaf1_.name=?
I found this topic in the forum but it was not stated as bug. Before filing a bug I would like to get some feedback. An example project with all mappings and classes can be downloaded here.
http://www.laliluna.de/HibernateTest.zip