openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin <>
Subject Re: Restrict collection items
Date Thu, 25 Dec 2008 06:32:29 GMT

No problem, but I'm sure my solution is too custom and simple to use it "as
I have made a descendant of DBDictionary and overridden this method:
public SQLBuffer toTraditionalJoin(Join join) {
        // do column joins
        SQLBuffer buf = new SQLBuffer(this);
        int count = 0;
        for (int i = 0; i < from.length; i++, count++) {
            if (count > 0)
                buf.append(" AND ");
            buf.append(" = ");

            // My addition is here: 
            if (inverse && to[i].getTable().containsColumn(DELETE_TS_COL))
                buf.append(" AND ");
buf.append(join.getAlias2()).append(".").append(DELETE_TS_COL).append(" IS
The point is that every table which I want to filter contains the column
with predefined name (DELETE_TS_COL constant), so I can easily add required
In fact I have overridden one more method (getWhere()) to avoid adding
"entity.deleteTs is null" in each query and after entityManager.find(), but
it is obviously out of scope of this topic.

Of course it would be great if OpenJPA supports adding filter conditions for
loading entities and collections. There should be a way to define such
filters as annotations and through EntityManager interface. The latter is
needed because some filters may be dynamic - e.g. I want to switch off
DELETE_TS filtering when I need to work with "deleted" instances.


Pinaki Poddar wrote:
> Hi,
>    > I have managed to modify generated SQL by overriding a couple of
> DBDictionary methods, 
>   That's excellent. Having to specify a conditional filter on collection
> is a useful and often requested feature.
>   If you post the changes, they can be integrated with the code base. 

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

View raw message