Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Prevent caching

Hi list,

i have some issues with the cache of eclipselink.

If i use the returned entity class of a named query and change it (set
a new value of a member) and then use the same named query again, the
returned object i get from the second query has the changed member and
not the value from database.
let me explain with some pseudo-code to make it more clearly:

<snip>
class A {
  private List<B> bList;
}

// ... later in code

EntityManager em = getEntityManager();
Query qry = em.createNamedQuery("NameOfTheNamedQuery");
// set some named parameters ...
Object result = qry.getSingleResult();

// the result is the entity A and contains a List of B
// now change the member
result.setBList(otherBList);

EntityManager em = getEntityManager();
Query qry = em.createNamedQuery("NameOfTheNamedQuery");
// set some named parameters ...
Object result = qry.getSingleResult();

// now result contains "otherBList" and not a new loaded List of B
from database.
</snap>

I've tried 3 different methods to avoid caching:

- @Cache(alwaysRefresh = true) to the entity class A which contains
the list of B's, B itself and both together.

- in the persistent.xml:
<property name="eclipselink.cache.size.default" value="0"/>
<property name="eclipselink.cache.type.default" value="None"/>
<property name="eclipselink.cache.shared.default " value="false" />
<property name="eclipselink.query-results-cache" value="false"/>

- and after getting the EntityManager instance:
em.getEntityManagerFactory().getCache().evictAll();

Nothing has helped to get every time a new loaded list from database,
the result always contains the altered list I've set before.

What can I do to get always a new loaded list from database?


Back to the top