# \[Hibernate JCache\] Creating CacheManager per SessionFactory

**URL:** https://discourse.hibernate.org/t/hibernate-jcache-creating-cachemanager-per-sessionfactory/2826
**Category:** Hibernate ORM
**Created:** [June 11, 2019, 8:36am UTC](https://discourse.hibernate.org/t/hibernate-jcache-creating-cachemanager-per-sessionfactory/2826 "2019-06-11T08:36:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Andrey\_Korovin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/andrey_korovin/32/637_2.png) [@Andrey\_Korovin](https://discourse.hibernate.org/u/Andrey_Korovin)
#### Post date: [June 11, 2019, 8:36am UTC](https://discourse.hibernate.org/t/hibernate-jcache-creating-cachemanager-per-sessionfactory/2826/1 "2019-06-11T08:36:51Z")

</div>

Hi guys,  
After migration from Hibernate Ehcache module to Hibernate JCache we are facing the issue with shared CacheManager between different spring contexts in tests. This issue is causing problem when you are trying to access to cache which was closed during shutdown by some spring context.

In Hibernate Ehcache we were using `org.hibernate.cache.ehcache.EhCacheRegionFactory` which is working as expected(creates new CacheManager each time), but in Hibernate JCache there is only `org.hibernate.cache.jcache.JCacheRegionFactory` which returns same CacheManager whatever SessionFactory is used.

Hibernate userguide is saying:

```auto
Example 23. JCache configuration
<property
    name="hibernate.javax.cache.provider"
    value="org.ehcache.jsr107.EhcacheCachingProvider"/>
<property
    name="hibernate.javax.cache.uri"
    value="file:/path/to/ehcache.xml"/>

Only by specifying the second property `hibernate.javax.cache.uri` will you be able to have a `CacheManager` per `SessionFactory` .

```

But even we’ve added `hibernate.javax.cache.uri` to config we are having same issue. Also, from the source code it’s not clear what is the relation between uri for config and creation of CacheManager per SessionFactory.

Please advise how to deal with this issue.
