开发者

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Crit开发者_如何学Pythoneria API?

select order from ORDER as order,ITEM as item 
where item.itemID like 'ITM_01' and item in elements(order.items)


To answer the question in the title - no, there's no direct equivalent for elements() in Criteria API.

However, your query's use of elements() is superfluous. It can instead be more simply rewritten as

select order from ORDER as order
  where order.items.itemID like 'ITM_01'

Equivalent criteria would have to use nested criteria instance to access collection:

session.createCriteria(Order.class)
 .createCriteria("items")
 .add(Restrictions.like("itemID", "ITM_01"));

Another alternative is to use aliases:

session.createCriteria(Order.class)
 .createAlias("items", "item")
 .add(Restrictions.like("item.itemID", "ITM_01"));

Note that you don't need to use LIKE for fixed value, you can use simple equality instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜