Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Don't get programmatical cache invalidation to work [JPA]
icon9.gif  Don't get programmatical cache invalidation to work [JPA] [message #788063] Wed, 01 February 2012 10:03 Go to next message
Marian Seitner is currently offline Marian SeitnerFriend
Messages: 4
Registered: October 2009
Junior Member
Hi,

my database is externally modified so at some point I need to invalidate the entity cache in my web application.

I wrote a servlet which basically does the following:

@PersistenceContext // injected via Spring
EntityManager em;

JpaEntityManager nativeEm = em.unwrap(JpaEntityManager.class);

// this method always throws an NPE
Session session = nativeEm.getSession();

session.getIdentityMapAccessor().invalidateAll();


I also tried the other flavors of get*Session(), but none of them worked. What is the correct way to get access to an active session?

Thanks,
Marian


Environment:

  • GlassFish 3.1.1 w/ EclipseLink 2.3.0
  • MySQL 5.x

Re: Don't get programmatical cache invalidation to work [JPA] [message #788278 is a reply to message #788063] Wed, 01 February 2012 15:44 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
In JPA 2.0, you can use the http://docs.oracle.com/javaee/6/api/javax/persistence/Cache.html#evictAll() method to invalidate the EclipseLink caches. You'll need to inject the EntityManagerFactory and call http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManagerFactory.html#getCache().evictAll().

--Shaun
Re: Don't get programmatical cache invalidation to work [JPA] [message #788370 is a reply to message #788278] Wed, 01 February 2012 18:17 Go to previous message
Marian Seitner is currently offline Marian SeitnerFriend
Messages: 4
Registered: October 2009
Junior Member
Thanks, works like a charm!

However I wonder what would have been the "hard way" using the EclipseLink session... could you give me some pointers? Especially for the problem of not getting a session through the EntityManager...

Thanks,
Marian
Previous Topic:Custom MetadataSource and Dynamic Weaving
Next Topic:Don't get programmatical cache invalidation to work [JPA]
Goto Forum:
  


Current Time: Fri Apr 26 07:27:50 GMT 2024

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

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

Back to the top