title: Set parameters for L2 cache with Hibernate, EhCache and Wildlfy
body: <p>I have application which use Hibernate with EhCache as a second level cache provider. The application deployed on Wildfly 8.2. 
  The second level cache configured and works as expected but I cannot figure out how to provide a separate configuration for second level cache in echache.xml configuration in a generic way. Currently my setup looks like:</p>
  
  <p>Entitiy: </p>
  
  <pre class="lang-java prettyprint-override"><code>     /**
       * The Country class
       */
      @Entity
      @Table(name = "country")
      @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "ENTITY_L2_CACHE")
      public class Country extends AbstractPersistentEntity {}
  </code></pre>
  
  <p>The pesistence.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="app_PU" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;jdbc/app&lt;/jta-data-source&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.enable_lazy_load_no_trans" value="true"/&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/&gt;
              &lt;property name="hibernate.transaction.jta.platform" value="com.torqueits.pos.jpa.ProxyJtaPlatform"/&gt;
              &lt;!-- enabling L2 cache --&gt;
              &lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/&gt;
              &lt;property name="hibernate.generate_statistics" value ="false" /&gt; 
              &lt;property name="hibernate.cache.use_second_level_cache" value="true"/&gt;
              &lt;property name="hibernate.cache.use_query_cache" value="false"/&gt;
              &lt;property name="hibernate.cache.ehcache.statistics" value="false"/&gt;
              &lt;property name="hibernate.generate_statistics" value="false"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>And the ehcache.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" name="torqueCacheManager"&gt;
      &lt;diskStore path="java.io.tmpdir"/&gt;
      &lt;!-- Fail safe default cache--&gt;
      &lt;defaultCache
          maxElementsInMemory="10000"
          eternal="false"
          ...
          memoryStoreEvictionPolicy="LRU"&gt;        
      &lt;/defaultCache&gt;
      &lt;cache name="ENTITY_L2_CACHE"  
         maxElementsInMemory="10000"
         ...
         diskExpiryThreadIntervalSeconds="120"
         memoryStoreEvictionPolicy="LRU"/&gt;        
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>While I configured entities to use ENTITY_L2_CACHCE as a region for the second level cache the actual name used by hibernate is </p>
  
  <blockquote>
    <p>application.war#app_PU.ENTITY_L2_CACHE</p>
  </blockquote>
  
  <p>Which is uses deployment name plus persistence unit name as a prefix for region. I don't have control over the deployment name so I cannot put 'application.war#app_PU.ENTITY_L2_CACHE' into the ehcache.xml. I'm not sure if this related to hibernate or wildfly server. </p>
  
  <p>Is there any ways to configure parameters for second level cache which is not bind to specific deployment name?</p>