Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Invalidation and JPA(EntityManager returns invalid/stale entities)
Invalidation and JPA [message #516591] Wed, 24 February 2010 13:52 Go to next message
No real name is currently offline No real nameFriend
Messages: 2
Registered: February 2010
Junior Member

i have a problem with manually invalidating a entity in the cache using the identitymap api. The object is invalid but it is not refreshed when it is accessed again.

The following code snipped executes only a single SQL but it should execute another one to refresh the invalid entity:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
EntityManager em = emf.createEntityManager();

MyEntity entity = em.find(MyEntity .class, "20");

Session eclipselinkSession = ((JpaEntityManager)em.getDelegate()).getActiveSession();		

eclipselinkSession = ((JpaEntityManager)em.getDelegate()).getServerSession();		

boolean valid = eclipselinkSession.getIdentityMapAccessor().isValid(entity);


entity = em.find(MyEntity.class, "20");		
valid = eclipselinkSession.getIdentityMapAccessor().isValid(entity);



Is it even possible to use the invalidation api together with JPA? Did i miss something else?

Tested it with EclipseLink 1.02, 1.1.1, 2.0

Regards Axel

Edit: is this possibly related to this:

With the native API from eclipselink the entity is refreshed as expected
eclipselinkSession.readObject(new MyEntity("20"));

[Updated on: Thu, 25 February 2010 12:24]

Report message to a moderator

Re: Invalidation and JPA [message #516974 is a reply to message #516591] Thu, 25 February 2010 16:30 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1296
Registered: July 2009
Senior Member

The persistence context has its own cache that is being used, inorder to keep transactions issolated. Because you are using the same EntityManager on an extended persistence context for the second find, it returns the same managed entity without having to go to the shared cache (where the object is marked as invalid). You will need to clear your em after you commit your transaction to clear out the persistence context's cache for the second find to cause a refresh.

Best Regards,
Previous Topic:JPA / EclipseLink, Spring 2.5 and Tomcat 6
Next Topic:Using Observable Lists within entity classes?
Goto Forum:

Current Time: Thu May 24 16:07:14 GMT 2018

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

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

Back to the top