title: Hibernate 2nd level cache
body: <p>Hi I've run into some problems with hibernate 2nd level cache.
  As cache provider I use ehcache.</p>
  
  <p>Part of config from persistence.xml</p>
  
  <pre><code>&lt;property name="hibernate.cache.use_second_level_cache" value="true"/&gt;
  &lt;property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" /&gt;
  &lt;property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml" /&gt;
  </code></pre>
  
  <p>I configure my entities using annotations so:</p>
  
  <pre>@Cache(region = "Kierunek", usage = CacheConcurrencyStrategy.READ_WRITE)
  public class Kierunek implements Serializable {</pre>
  
  <p>imports for those annotations are:
  <code>import org.hibernate.annotations.Cache;
  import org.hibernate.annotations.CacheConcurrencyStrategy;</code></p>
  
  <p>my ehcache.xml</p>
  
  
  
  <p></p>
  
  <pre><code>&lt;diskStore path="java.io.tmpdir" /&gt;
  
  &lt;defaultCache maxElementsInMemory="10000" eternal="false"
      timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
      diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
      diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
      memoryStoreEvictionPolicy="LRU" /&gt;
  
  &lt;cache name="Kierunek" maxElementsInMemory="1000"
      eternal="true" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>And anyone idea why i get following error ?</p>
  
  <pre><code>WARNING: Could not find a specific ehcache configuration for cache named [persistence.unit:unitName=pz2EAR.ear/pz2EJB.jar#pz2EJB.Kierunek]; using defaults.
  19:52:57,313 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=pz2EAR.ear/pz2EJB.jar#pz2EJB state=Create
  java.lang.IllegalArgumentException: Cache name cannot contain '/' characters.
  </code></pre>
  
  <p>solution is to add another property to persistence.xml</p>
  
  <pre><code>&lt;property name="hibernate.cache.region_prefix" value=""/&gt;
  </code></pre>
  
  <p>and that removes that faulty prefix big thx ruslan!</p>