<p>What are the steps required to enable Hibernate's second-level cache, when using the Java Persistence API (annotated entities)? How do I check that it's working? I'm using JBoss 4.2.2.GA.</p>

<p>From the Hibernate documentation, it seems that I need to enable the cache and specify a cache provider in <em>persistence.xml</em>, like:</p>

<pre><code>&lt;property name="hibernate.cache.use_second_level_cache"
          value="true" /&gt; 
&lt;property name="hibernate.cache.provider_class" 
          value="org.hibernate.cache.HashtableCacheProvider" /&gt; 
</code></pre>

<p>What else is required? Do I need to add <em>@Cache</em> annotations to my JPA entities?</p>

<p>How can I tell if the cache is working? I have tried accessing cache statistics after running a Query, but <em>Statistics.getSecondLevelCacheStatistics</em> returns null, perhaps because I don't know what 'region' name to use.</p>

[{'answer_id': 53992, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 3, 'selected': True, 'text': '<p>I believe you need to add the cache annotations to tell hibernate how to use the second-level cache (read-only, read-write, etc). This was the case in my app (using spring / traditional hibernate and ehcache, so your mileage may vary). Once the caches were indicated, I started seeing messages that they were in use from hibernate.</p>\n'}, {'answer_id': 54415, 'author': 'Peter Hilton', 'author_id': 2670, 'author_profile': 'https://Stackoverflow.com/users/2670', 'pm_score': 2, 'selected': False, 'text': '<p>Follow-up: in the end, after adding annotations, I have it working with EhCache, i.e.</p>\n\n<pre><code>&lt;property name="hibernate.cache.provider_class" \n          value="net.sf.ehcache.hibernate.EhCacheProvider" /&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/53562', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2670/']