Heath Thomann created OPENJPA-2586:
--------------------------------------
Summary: In correct relationship data returned when DataCache and
FetchPlans are used.
Key: OPENJPA-2586
URL: https://issues.apache.org/jira/browse/OPENJPA-2586
Project: OpenJPA
Issue Type: Bug
Components: datacache, jdbc
Affects Versions: 2.2.2, 2.1.2, 2.2.1.1, 2.4.1
Reporter: Heath Thomann
Priority: Critical
I have found a scenario that the wrong data is returned when the DataCache,
QueryCache, and FetchPlans are used. To explain, take these very simple
entities and relationship:
@Entity
public class Compra {
@Id
private int id;
@ManyToOne(fetch = FetchType.LAZY)
private Apostador apostador;
........
@Entity
public class Apostador {
@Id
private Long id;
......
Given these two entities, take this scenario:
Query q = em.createQuery("Select compra from Compra compra");
FetchPlan fetchPlan = q.unwrap(OpenJPAQuery.class).getFetchPlan();
fetchPlan.addField(Compra.class, "apostador");
List<Compra> results = (List<Compra>) q.getResultList();
em.clear();
assertNotNull("No results returned!", results);
for (Compra compra : results) {
assertNotNull("An 'apostador' should have been returned!",
compra.getApostador());
}
With this code, assume the DataCache and QueryCache are both enabled, and
assume there is a Compra with an Apostador in the database. When we execute
this code all works fine. However, if we execute the code back to back using
the same EntityManagerFactory, a Compra will be returned but its Apostador will
be null! If on the other hand, we execute the code 3 times in a row, where
there is a time lag between the 2nd and 3rd execution great than the DataCache
timeout, the correct data will be returned during the 3rd execution. This
shows that there is a problem when the DataCache, QueryCache, and a FetchPlan
are used. For more details please see the patch I've attached which contains a
test to recreate this issue as well as a proposed fix.
Thanks,
Heath Thomann
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)