-->
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.  [ 4 posts ] 
Author Message
 Post subject: Collection filtering strategy
PostPosted: Wed Nov 19, 2003 12:17 pm 
Newbie

Joined: Tue Nov 11, 2003 5:25 pm
Posts: 17
Location: Milwaukee, Wi
Hibernate 2.1b6, JDK 1.4.2_02

I have this situation:

- Parent has one-to-many Children
- Children objects/records are only viewable at a certain authorization level

My mapping for this association in Parent.hbm.xml is as follows:

Code:
<set
    name="children"
    lazy="true"
    inverse="true">
    <key column="PARENT_FK" />
    <one-to-many class="domain.Child"/>
</set>


There are many queries on the Parent, where the Parent object is returned. Some queries just need the Parent, so I don't want to disable lazy loading. What I would like to do is filter the set of Child objects when getChildren() is called according to a variable that symbolizes the authorization level.

Specifically; the Child table has a Hibernate-mapped column that contains the authorization level, and the threads executing queries have a ThreadLocal object that contains the user's authorization level. These levels should match in order for the user to view the Child data.

Is it possible to put this into the mapping file? If so, how would I do it?

Code:
<set
    name="children"
    lazy="true"
    inverse="true"
    where="child.authlevel=:authlevel">
    <key column="PARENT_FK" />
    <one-to-many class="domain.Child"/>
</set>


Is this possible? If so, how would the ":authlevel" variable get set when code calls the parent.getChildren() method? Would a filter() method be more appropriate?

Any ideas or thoughts would be appreciated. Thanks,
--D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 2:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No possible.

Maybe having a functional getChildren() using a mapped getHibernateChildren() would do the job.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 3:01 pm 
Newbie

Joined: Tue Nov 11, 2003 5:25 pm
Posts: 17
Location: Milwaukee, Wi
I think you're right, thanks for the reply.

-- D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 7:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a collection filter


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.