enter code here
我想对项目列表应用限制,因此只会检索给定日期的项目。
这是我的映射:
<class name="MyClass"
table="MyTable" mutable="false" >
<cache usage="read-only"/>
<id name="myId" column="myId" type="integer"/>
<property name="myProp" type="string" column="prop"/>
<list name="items" inverse="true" cascade="none">
<key column="myId"/>
<list-index column="itemVersion"/>
<one-to-many class="Item"/>
</list>
</class>
<class name="Item"
table="Items" mutable="false" >
<cache usage="read-only"/>
<id name="myId" column="myId" type="integer"/>
<property name="itemVersion" type="string" column="version"/>
<property name="startDate" type="date" column="startDate"/>
</class>
我试过这段代码:
Criteria crit = session.createCriteria(MyClass.class);
crit.add( Restrictions.eq("myId", new Integer(1)));
crit = crit.createCriteria("items").add( Restrictions.le("startDate", new Date()) );
这导致以下问题:
select ...
from MyTable this_ inner join Items items1_ on this_.myId=items1_.myId
where this_.myId=? and items1_.startDate<=?
其次是
select ...
from Items items0_
where items0_.myId=?
但我需要的是这样的:
select ...
from MyTable this_
where this_.myId=?
其次是
select ...
from Items items0_
where items0_.myId=? and items0_.startDate<=?
知道如何在项目列表上应用标准吗?