Hi,
Lets say I have 3 tables (position, item, subitem).
A position has 1..* items, and an item has 1..* subitems.
Now I wanna search for all positions with subitem.description like "xyz".
Code:
Session session = HibernateUtil.getSessionFactory().openSession();
criteria = session.createCriteria(Position.class, "pos");
criteria.createAlias("pos.items.subitems", "subitem", CriteriaSpecification.LEFT_JOIN);
criteria.add(Restrictions.like("subitem.description", "%xyz%"));
That way I get the exception:
Unknown column 'subitem1_.Description' in 'where clause'.But if I do first:
Code:
criteria.createAlias("pos.items", "item", CriteriaSpecification.LEFT_JOIN);
criteria.add(Restrictions.like("item.description", "%%"));
and then
Code:
criteria.createAlias("pos.items.subitems", "subitem", CriteriaSpecification.LEFT_JOIN);
criteria.add(Restrictions.like("subitem.description", "%xyz%"));
it works fine.
Any ideas?
Thanks Bona