disableHits will disable cache hits, so you should see two queries from two different EntityManager always access the database. In fact your named queries are not by primary key, so will always access the database. Perhaps enable logging in EclipseLink to see the SQL access.
What you may be seeing is that two queries in the same EntityManager will still get a cache hit. This is because the EntityManager represents a persistence and transactional context, so the same object must always be returned. To cause a refresh in the same EntityManager you must use refresh() or the "eclipseLink.refresh" query hint.
I have positive result with the following usage
@Entity
@Cache (
type=CacheType.WEAK,
expiry=600000,
alwaysRefresh =true,
disableHits=false,
coordinationType=CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES
)
@NamedQueries( {
@NamedQuery(name = "CodFlexCodesB.findAll",
query = "select o from CodFlexCodesB o"),
@NamedQuery(name = "CodFlexCodesB.timeValidity",
query = "SELECT em FROM CodFlexCodesB em " +
"WHERE em.codFlexCodeSystemsB.id = :id AND " +
"(em.startDate <= :endDate) AND (em.endDate >= :startDate OR em.endDate IS NULL) ",
hints = @QueryHint(name=QueryHints.CACHE_USAGE, value=CacheUsage.ConformResultsInUnitOfWork )
)
})
May be it helps.
elygre wrote:
While working with caching, I have customized a class descriptor, calling
"descriptor.disableCacheHits();". I figured that this would make multiple
calls to "em.find(key)" generate multiple SQL-statements to the database.
This does not happen, and then I wonder why. There is really not much else
going on, in terms of configuration and setup. Anything I need to switch on?
Eirik