开发者

How do you add join a table using Criteria class?

开发者 https://www.devze.com 2023-03-03 10:02 出处:网络
I am new to using Criteria, and i am trying to join tables on my query. This is my expected query set up
I am new to using Criteria, and i am trying to join tables on my query.
This is my expected query set up

Select * FROM ATable a INNER JOIN BTable b ON a.id = b.f开发者_开发技巧k_id WHERE fk_pname = ":cat";

Do you know how i can add the "INNER JOIN BTable b ON a.id = b.fk_id"?

I already added in instance, but not sure how to add the other table. Criteria criteria = this.getSession().createCriteria(ATable.class);

Thanks again for all your help


Something like this will do it - Criteria criteria = this.getSession().createCriteria(ATable.class) .createAlias("btable","b") .add(Restrictions.eq("b.pname",":cat")

The string 'btable' refers to the property name in the ATable entity class that corresponds to the BTable entity.

0

精彩评论

暂无评论...
验证码 换一张
取 消