Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » container managed transactions + shared cache eviction
container managed transactions + shared cache eviction [message #1008215] Mon, 11 February 2013 14:27 Go to next message
Andreas S is currently offline Andreas S
Messages: 5
Registered: February 2013
Junior Member
Hi there Smile
I'm trying to understand how I can evict the shared cache from an EJB.

Obviously, this doesn't work:

@PersistenceContext(unitName="pu")
private EntityManager em;

public void persist(Entity entity) {
  em.persist(entity);
  em.flush();
  em.getEntityManagerFactory().getCache().evictAll();
}


Since the transaction is container managed and the cache is evicted before the transaction completes, there still is stale data.

Any suggestion?
Re: container managed transactions + shared cache eviction [message #1008286 is a reply to message #1008215] Mon, 11 February 2013 18:59 Go to previous messageGo to next message
Super User is currently offline Super User
Messages: 9
Registered: January 2013
Junior Member
Hi,
In which way do you check is data stale?
Re: container managed transactions + shared cache eviction [message #1008302 is a reply to message #1008286] Mon, 11 February 2013 20:00 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1023
Registered: July 2009
Senior Member
em.getEntityManagerFactory().getCache().evictAll(); operates on the shared second level cache, but the EntityManager itself still has a cache of managed entities. You can simply call em.clear() after em.flush() to detach all managed entities.
Re: container managed transactions + shared cache eviction [message #1008388 is a reply to message #1008286] Tue, 12 February 2013 09:47 Go to previous message
Andreas S is currently offline Andreas S
Messages: 5
Registered: February 2013
Junior Member
Super User wrote on Mon, 11 February 2013 13:59
Hi,
In which way do you check is data stale?


By comparing the JAX-RS responses and the database content.

Quote:
em.getEntityManagerFactory().getCache().evictAll(); operates on the shared second level cache, but the EntityManager itself still has a cache of managed entities. You can simply call em.clear() after em.flush() to detach all managed entities.


thank you Smile
em.flush();
em.clear();
em.getEntityManagerFactory().getCache().evictAll();


Seems to work.
Need to do a bit more testing.
Previous Topic:Version 2.4.2 M5 - The query contains a malformed ending
Next Topic:EclipseLink merge fails to insert
Goto Forum:
  


Current Time: Sun Sep 21 16:25:21 GMT 2014

Powered by FUDForum. Page generated in 0.02534 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software