Почему Hibernate не видит конфигурацию ehcache.xml?
Properties:
spring.cache.jcache.config=classpath:ehcache.xml
spring.jpa.properties.javax.persistence.sharedCache.mode=ENABLE_SELECTIVE
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=jcache
spring.jpa.properties.hibernate.cache.use_reference_entries=true
Над классом:
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "defaultCache")
@Immutable
ehcache.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache-template name="dictionary">
<expiry>
<ttl unit="hours">24</ttl>
</expiry>
<resources>
<heap unit="entries">200</heap>
<offheap unit="MB">1</offheap>
</resources>
</cache-template>
<cache alias="defaultCache" uses-template="dictionary"/>
</config>
Но в консоли такое сообщение:
2023-01-09 12:32:07.605 WARN 17348 --- [ main] org.hibernate.orm.cache : HHH90001006: Missing cache[defaultCache] was created on-the-fly. The created cache will use a provider-specific default configuration: make sure you defined one. You can disable this warning by setting 'hibernate.javax.cache.missing_cache_strategy' to 'create'.
2023-01-09 12:32:07.643 INFO 17348 --- [ main] org.ehcache.core.EhcacheManager : Cache 'defaultCache' created in EhcacheManager.
Почему Hibernate не видит конфигурацию?
P.S.: Пробовал указать в настройках таким образом:
spring.jpa.properties.hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider
spring.jpa.properties.hibernate.javax.cache.uri=file:ehcache.xml
и тот же результат.
P.S.2: Если в ehcache.xml добавить:
<cache alias="status-by-id" uses-template="dictionary">
<key-type>java.lang.Long</key-type>
<value-type>ru.module.entity.CheckStatus</value-type>
</cache>
то создается Ehcache MBean и кэш второго уровня работает нормально, но в консоли сообщение всё равно высвечивается и Hibernate создает второй CacheManager с настройками по умолчанию.
P.S.3: Пробовал добавить в ehcache.xml:
<service>
<jsr107:defaults default-template="dictionary">
<jsr107:cache name="defaultCache" template="dictionary"/>
</jsr107:defaults>
</service>
безрезультатно.
P.S.4: Пробовал добавить в properties:
spring.cache.cache-names=defaultCache
Создается defaultCache:
2023-01-09 17:47:35.880 INFO 18580 --- [ main] org.ehcache.jsr107.ConfigurationMerger : Configuration of cache defaultCache will be supplemented by template dictionary
2023-01-09 17:47:35.883 INFO 18580 --- [ main] org.ehcache.jsr107.ConfigurationMerger : Cache defaultCache will use expiry configuration from template dictionary
2023-01-09 17:47:35.891 INFO 18580 --- [ main] .e.s.o.t.o.p.UpfrontAllocatingPageSource : Allocating 1MB in chunks
2023-01-09 17:47:35.895 INFO 18580 --- [ main] org.ehcache.core.EhcacheManager : Cache 'defaultCache' created in EhcacheManager.
Но Hibernate по прежнему его не видит и создает свой кэш.