Level two cache may not be enabled when using @Cacheable without/instead of @Cache

Description

  • Multiple JPA persistence units are deployed (some enable caching via hibernate.cache.use_second_level_cache=true and some do not)

  • Entities are annotated with @javax.persistence.Cacheable

  • Randomly (not reproducible at will), caching is not enabled (queries that should resolve in cache consistently go to the database)

  • DEBUG logging shows that, when the issue occurs, there are no log entries like ... [org.hibernate.cache.infinispan.InfinispanRegionFactory] Building entity cache region ...

  • The same issue has never been reproduced when @org.hibernate.annotations.Cache is used for entities and cache regions are consistently (based on DEBUG trace) seen to be created for associations (which can only be made cacheable via @Cache)

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 6 / Hibernate 4

  • Red Hat JBoss Enterprise Application Platform (EAP) 7 / Hibernate 5

Activity

Show:
Stephen Fikes
February 22, 2017, 9:47 PM

Not sure if this is reproducible in Hibernate 5.

Stephen Fikes
February 27, 2017, 5:12 PM
Edited

I've attached a testcase (see included README) which I used to reproduce the issue with

  • EAP 6 (Hibernate 4)

  • EAP 7 (Hibernate 5.0.11)


The testcase uses a Byteman rule to control which thread wins the race to initialize AnnotationBinder.DEFAULT_CACHE_CONCURRENCY_STRATEGY. Specifically, the EAP*AnnotationBinderDetermineCacheConcurrencyStrategyEnableSleep rule causes the thread deploying the cache enabled unit to sleep when it hits AnnotationBinder.determineCacheConcurrencyStrategy(). Consequently, the unit with cache disabled sets the default strategy and this determines the value subsequently returned on all threads.

Gail Badner
March 13, 2017, 10:25 PM

Fixed in master.

Assignee

Gail Badner

Reporter

Stephen Fikes

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure