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: filtering collections on object graph
PostPosted: Fri Sep 15, 2006 11:06 am 

Joined: Fri Sep 15, 2006 2:09 am
Posts: 11
Assume the following object graph (an example):


person is the owning class.
contacts is a collection (one-to-many), city and address are many-to-one relationships.
name is a string attribute on city.

Now I would like the following:

Get all persons which contacts are in a specific city. It should return person objects
where ONLY contacts are included where the city name equals a specific string. So not all
contacts are loaded but a subset of them.

As far as I read the documentation, there are two ways for doing that:

1. Use filter-defs on the collection and set the filter on-demand by using enableFilter on
the session
2. Filter the collections after getting the person objects (with perhaps fully loaded contacts collection)
with createFilter on the session.

I'm unhappy with the two approaches. Using filter-defs COULD work for me if the WHOLE condition could be
changed at runtime - not only parameters in it. I need this, because the user is able to search in
different attributes for n-values with like. So I would have to dynamically create the where clause
(e.g. "where name like '%:n1%' or name like '%:n2%'"...). Another question regarding filter-defs is lazy loading
and different sessions. The documentation says, that the enableFilter works only for the current session. What
happens if I load the persons in one session with the filter enabled, and attach the persons to a different session.
Then I call getContacts. I assume, that the contacts won't be filtered because the filter isn't set on the new
session, right? BTW: the documentation is poor on this point...

The 2nd way, using createFilter on already loaded collections, isn't really a good solution for me either. That would
mean that I have a second collection of contacts parallel to the person.contacts collection. I can't navigate to
it through the person class. I also have to use the where clause for selecting specific contacts twice. One for the person
select and one for the collection filter. I would like to keep the object graph navigation...

So, is there a way to handle this nicely?

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.