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]
Don't get programmatical cache invalidation to work [JPA] [message #788067] Wed, 01 February 2012 10:03 Go to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 59
Registered: July 2009
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 #788276 is a reply to message #788067] 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 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 18:17 Go to previous messageGo to next message
Marian Seitner is currently offline Marian SeitnerFriend
Messages: 5
Registered: July 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
Re: Don't get programmatical cache invalidation to work [JPA] [message #788380 is a reply to message #788373] Wed, 01 February 2012 18:35 Go to previous message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
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: Thu Nov 07 14:30:10 GMT 2024

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

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

Back to the top