-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: filter list with Criteria
PostPosted: Mon Jul 13, 2009 10:51 am 
Newbie

Joined: Mon Jul 13, 2009 10:46 am
Posts: 2
I have a list with one-to-many relationship. When loading MyClass, I want to apply restrictions on the list of items, so only items from a given dates will be retrieved.

Here are my mappings:
Code:
        <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>

I tried this code:

Code:
   Criteria crit = session.createCriteria(MyClass.class);
    crit.add( Restrictions.eq("myId", new Integer(1)));
    crit = crit.createCriteria("items").add( Restrictions.le("startDate", new Date()) );


which result the following quires:

Code:
    select ...
    from MyTable this_ inner join Items items1_ on this_.myId=items1_.myId
    where this_.myId=? and items1_.startDate<=?


followed by

Code:
    select ...
    from Items items0_
    where items0_.myId=?


But what I need is something like:

Code:
    select ...
    from MyTable this_
    where this_.myId=?


followed by

Code:
    select ...
    from Items items0_
    where items0_.myId=? and items0_.startDate<=?


Any idea how I can apply a criteria on the list of items?

Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.