-->
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: how to have getChildren() return a subset of the Collection?
PostPosted: Mon Jan 05, 2004 4:05 pm 
Newbie

Joined: Fri Jan 02, 2004 3:23 pm
Posts: 3
Hi,

I have a Child / Parent relationship.
Only children have a property (ryear). When I do parent.getChildren(), I would like to only receive the children WHERE RYEAR='2003'

I have this condition harcoded in the mapping, it works fine, but I don't want to hardcode it.
I have searched the doc + this forum, but I can't find a way to do it.

I can do session.filter(parent.getChildren(), "WHERE this.ryear='2003'"),
but it's next time I call parent.getChildren(), it will return the full list again.

I want to get the same exact result as specify the WHERE clause in the mapping, but I don't want to hardcode the condition in the mapping.

Is this possible?

Thanks.


Here's my actual mapping:
Code:
<hibernate-mapping>

   <class name="model.hibernate.beans.Scientists"
     <id name="id" column="SCID" type="string">
       <generator class="native"/>
     </id>
     <property name="firstName" column="FNAME" type="string"/>
     <property name="lastName" column="LNAME" type="string"/>

     <bag name="ipidOridScid" lazy="false"  cascade="all" where="RYEAR='2003'">

         <key column="SCID"/>
         <one-to-many class="model.hibernate.beans.IpOrSc"/>
    </bag>
</class>
<hibernate-mapping>


<class name="model.hibernate.beans.IpOrSc" table="IPID_ORID_SCID">
  <composite-id
        name="id"
        class="model.beans.IpOrScKey"
        >
        <key-many-to-one name="ipId" class="model.hibernate.beans.IProjects" column="IPID"/>
        <key-property name="orId" type="string" column="ORID"/>
        <key-many-to-one name="scId" class="model.hibernate.beans.Scientists" column="SCID"/>
  </composite-id>

  <property name="role" type="string" column="ROLE"/>
  <property name="ryear" type="string" column="RYEAR"/>

   </class>



Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 5:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no.

Think about it ...What should hibernate do when you come back with that object and the colleciton only contains 5 out of 10 real items ? Should it delete those 5 missing items ? ;)

Store the filtered result somewhere and use that instead.

_________________
Max
Don't forget to rate


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.