-->
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.  [ 2 posts ] 
Author Message
 Post subject: Collection (man-to-many) filtering
PostPosted: Wed Aug 18, 2004 4:51 pm 
Newbie

Joined: Wed Aug 18, 2004 4:26 pm
Posts: 1
I have the following mapping and I would like to find out if there's a better way to filter the results of a collection. I want InventoryItem to contain only the "promo" items where promotions.offer_ends is a date in the future.

The current solution using "when=" works but I'm not sure how portable it is. Is there a more Hibernatish way?

Thanks,
Brady

Hibernate version:
2.1.2

Mapping documents:
Code:
<hibernate-mapping>
    <class
        name="com.brady.InventoryItem"
        table="inventory_items"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="iid"
            type="java.lang.Integer"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <set
            name="promos"
            table="items2promos_do"
            lazy="true"
            inverse="true"
            cascade="none"
            sort="unsorted"
            where="promotion1_.offer_ends > NOW()"
        >
              <key
                  column="iid"
              >
              </key>
              <many-to-many
                  class="com.brady.Promotion"
                  column="promo_id"
                  outer-join="auto"
               />

        </set>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 5:17 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
It is not portable at all since your embedded where clause contains (in your case) statements specific to your particular database.

Why not declaring your set lazy and filter the collection on retrieve when you need it ? Something like:

Code:
Collection promos = session.filter(inventoryItem.getPromos(), "where this.offer_ends > ?", new Date(), Hibernate.TIMESTAMP);



This code is trully portable and should do the trick...

BTW: have a look at the doc, Chapter 9.3.4...


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

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.