You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Randy Watler <wa...@wispertel.net> on 2009/02/07 00:21:25 UTC

Query Cache Eviction Behavior

Hey guys,

I am in the middle of porting the Apache Jetspeed Portal from OJB to JPA 
and JTA using Spring and Extended EntityManagers. I am using the 
released version of JPA, OpenJPA 1.2.0. So far so good, but I do have a 
question concerning eviction from the query cache: if I have a 
relationship between two objects that is manifest only in JPQL 
statements, will inserts against one object table clear a query cache 
that contains results for the other object?

Here is a more detailed description of the situation.

@Entity
@NamedQuery (name="ABA", query="select a from A a, B b, A a2 where a2.name = :name and a2.id = b.id0 and b.id1 = a.id")
Class A
{
    @Id
    private Long id;
    @Basic
    private String name;
    ...
}

@Entity
Class B
{
    @Id
    private Long id0;
    @Id
    private Long id1;
    ...
}

Note the NamedQuery is the only relationship between class A and B Open 
JPA could be aware of since there are no *ToMany or *ToOne declared. 
Here is what I am observing based on trace logging:

1. Query for a list of A using query ABA and get no results, (OpenJPA 
generates and executes a correct select SQL),
2. Persist a new instance of B such that the original query should be 
satisifed, (OpenJPA generates and executes the corresponding insert 
SQL), and
3. Reissue the original query for a list of A using query ABA: 
unexpectedly returns no results, (OpenJPA indicates a cache hit and no 
SQL is logged).

I can easily imagine that OpenJPA would not automatically find and 
maintain this programmatic relationship between A and B. However, the 
documentation on query cache eviction seems to claim it might because 
clearly B is in the "access path" of A based on the ABA query. 
Consequently, it claims query results for A would have been cleared by 
the insert of a B instance.

No doubt there are work arounds here including manual eviction based on 
class A and I am going to start experimenting to find the one that works 
best in this case. I am also going to look into using the 'timestamp' 
eviction policy to see if that helps. I am posing the question though to 
make sure I am not totally in left field. I assume that if I actually 
modeled the relationships between A and B explicitly, I would not have 
run into this behavior, correct?

Thanks for the assistance/clarification in advance,

Randy Watler
Jetspeed2 Committer