openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From baileyby <>
Subject Filtering Results of a Mapped Relationship
Date Wed, 23 Dec 2009 20:22:44 GMT

Is there a way to filter children of a mapped relationship?

For example, I have a simple 3-tiered object structure,

Person   --(OneToOne)-->   AddressChain --(OneToMany using a simple 2 column
join table)--> Address

In the interest of keeping historical data, I use a status column on records
in the Address table, "Active" and "Deleted"   When I query to get a
"Person" object, I only want it to contain Address objects that are
"Active."  Unfortunately, doing a simple query like the one below doesn't
work, because what happens is that it fetches the person, and then
separately under the covers goes and finds ALL associated address chains and
addresses via the mapping relationship, including the ones marked Deleted. 
I don't see any annotations to instruct the mapping to filter by status (at
least, in OpenJPA.  It seems like hibernate may have a filtering
capability).  Any ideas?  Thanks in advance.

SELECT p from Person p, Address a WHERE and a.status="Active"

I have also tried variations such as the following to no avail.
SELECT p, c, a from Person p, AddressChain c, Address a WHERE and

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message