java - Hibernate Criteria: hibernate left join without association -
i hibernate newbie , have below query. working expected. these 2 tables not associated. there way same result using criteria api or how can run query via hibernate ? appreciated.
select p.title, c.content posts p left join comments c on p.id = c.post_id p.status = 'a' , (p.title ilike '%r%' or c.content ilike '%r%');
criteria api needs path between entities, i'm not sure join done using criteria api. better hql if have hibernate >= 5.1:
select p.title, c.content org.example.posts p left outer join org.example.comments c on p.id = c.id p.status = 'a' , (lower(p.title) '%r%' or lower(c.content) '%r%');
still, stick using sql queries hibernate or better still, create association between posts , comments.
Comments
Post a Comment