openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Watler <>
Subject Query Cache Eviction Behavior
Date Fri, 06 Feb 2009 23:21:25 GMT
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.

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

Class B
    private Long id0;
    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

View raw message