|Re: Clear object from cache with class and id [message #1014317 is a reply to message #1014197]
||Mon, 25 February 2013 15:28
| Chris Delahunt
Registered: July 2009
Chances are that you are not seeing two objects in the cache with the same ID (since the objects are cached based on their ID), and instead are seeing the object referenced by the cache being different from one referenced be a relationship in the cache. For example B->A' where B is cached, while A is cached directly. If this is the case, B would need to be evicted so that it is rebuilt and references the A from the cache. |
The two methods affect different layers of the cache:
affects the active Session, which would be the UnitOfWork or first level cache while
affects the ServerSession's shared cache if it is being used.
In my opinion though, the question should be how is this occurring rather than how to fix it once it does, as I don't know how you are detecting the problems that can occur. I've seen it occur when modifying read-only objects from the cache, something that should be avoided. You might be able to turn off the read-only hint and see if the problem goes away, then check that you are not mistakenly modifying the returned objects somehow without having to add protection for the error case.
|Re: Clear object from cache with class and id [message #1014353 is a reply to message #1014317]
||Mon, 25 February 2013 16:39
| Filipp A.
Registered: February 2010
Thanks for your explanation,|
i am sure, that my problem is with session cache, if i turn the cache off (PersistenceUnitProperties.CACHE_SHARED_DEFAULT, false) everything is fine.
my "standard" use of db is like:
1. get ReadOnly list of objects
2. if must be edited -
2.1 load ReadWrite Object with em.load()
2.2 merge to DB with em.merge()
2.3 update list with ReadOnly object
maybe exists any "best practice" for my case ?
and one more question - if object,that must be removed from cache, has many x to many, x to x relations (every object fetch = eager), is it enough to call ((JpaEntityManager)em.getDelegate()).getActiveSession().getIdentityMapAccessor().removeFromIdentityMap(id, mainObjectClazz) to remove all of subobject from the cache or not ?
Powered by FUDForum
. Page generated in 0.02662 seconds