Skip to main content

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

Hello,

In your code, what exactly is getEntityManager() returning? If they are seperate entitymanagers, they should be transactionally issolated - and therefore unable to see changes made in other Ems until the transaction commits to the database. So you might want to check that the em returned from getEntityManager() is indeed a new EntityManager rather than the previous one used to execute the query. If it is the same one, then you will either need to clear the em, refresh the entity with the changes, or use the EclipseLink refresh query hint (ex query.setHint(QueryHints.REFRESH, false); )

Best Regards,
Chris

On 30/11/2010 9:30 AM, Christian (VuuRWerK) Seifert wrote:
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?
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top