Hyperernate API for "elements ()"

Is it possible to implement the following query using the criteria API?

select order from ORDER as order,ITEM as item where item.itemID like 'ITM_01' and item in elements(order.items) 
+4
source share
1 answer

To answer the question in the title - no, there is no direct equivalent for elements() in the criteria API.

However, using the elements() query is redundant. Instead, you can simply rewrite it as

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

Equivalent criteria would be to use an instance of nested criteria to access the 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 do not need to use LIKE for a fixed value, you can use simple equality instead.

+3
source

All Articles