If you do this:
Code:
List cats = session.createCriteria(Cat.class)
.createCriteria("kittens").createAlias("kittens.mother", "mother")
.add(Restrictions.or(
Restrictions.like("name","F%"),
Restrictions.like("mother.name","F%")
)
).list();
Hibernate seems to get totally confused. The query it tries to execute is:
Code:
select
this_.id as id0_2_,
this_.birthdate as birthdate0_2_,
this_.mother_id as mother7_0_2_,
this_.sex as sex0_2_,
this_.weight as weight0_2_,
this_.name as name0_2_,
this_.subclass as subclass0_2_,
domesticca1_.id as id0_0_,
domesticca1_.birthdate as birthdate0_0_,
domesticca1_.mother_id as mother7_0_0_,
domesticca1_.sex as sex0_0_,
domesticca1_.weight as weight0_0_,
domesticca1_.name as name0_0_,
domesticca5_.id as id0_1_,
domesticca5_.birthdate as birthdate0_1_,
domesticca5_.mother_id as mother7_0_1_,
domesticca5_.sex as sex0_1_,
domesticca5_.weight as weight0_1_,
domesticca5_.name as name0_1_
from
cats this_
inner join
cats domesticca1_
on this_.id=domesticca1_.mother_id
left outer join
cats domesticca5_
on domesticca1_.mother_id=domesticca5_.id
where
(
domesticca1_.name like ?
or mother2_.name like ?
)
Which results in this error:
Code:
ORA-00904: "MOTHER2_"."NAME": invalid identifier
Because there is no mother2_ table in the from clause. I think that even if this worked, it would return cats whose mother start with f and whose mother's mother starts with f.