Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Don't get programmatical cache invalidation to work [JPA]
Don't get programmatical cache invalidation to work [JPA] [message #788067] Wed, 01 February 2012 05:03 Go to next message
Eclipse UserFriend
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 #788276 is a reply to message #788067] Wed, 01 February 2012 10:44 Go to previous messageGo to next message
Eclipse UserFriend
In JPA 2.0, you can use the Cache.evictAll() method to invalidate the EclipseLink caches. You'll need to inject the EntityManagerFactory and call emf.getCache().evictAll().

--Shaun
Re: Don't get programmatical cache invalidation to work [JPA] [message #788373 is a reply to message #788276] Wed, 01 February 2012 13:17 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Don't get programmatical cache invalidation to work [JPA] [message #788380 is a reply to message #788373] Wed, 01 February 2012 13:35 Go to previous message
Eclipse UserFriend
You should have called getServerSession() on the JpaEntityManager. The ServerSession is the object that underlies the EntityManagerFactory.

--Shaun
Previous Topic:Don't get programmatical cache invalidation to work [JPA]
Next Topic:JPA Partitioning and Spring
Goto Forum:
  


Current Time: Fri Jul 04 04:47:07 EDT 2025

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

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

Back to the top