Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1064493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:56:51+00:00 2026-05-16T18:56:51+00:00

I found some instructions how to configure pure hibernate to use EHCache. But I

  • 0

I found some instructions how to configure pure hibernate to use EHCache. But I can’t find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider.

edit//
Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:56:51+00:00Added an answer on May 16, 2026 at 6:56 pm

    I found some instructions how to configure pure hibernate to use EHCache. But I can’t find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider.

    The way you configure the L2 cache provider with JPA is similar is similar to raw Hibernate.

    By default, Hibernate 3.5 ships with EhCache 1.5 (see Configure Ehcache as a Second Level Cache) and if you want to use the official cache provider provided by Hibernate (in hibernate-ehcache if you are using Maven), declare:

    <!-- This is the provider for Ehcache provided by Hibernate, using the "old" SPI -->
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
    

    If you want to use EhCache 2.x, you’ll need to use the provider provided by EhCache which supports the new Hibernate 3.3/3.5 SPI with its CacheRegionFactory). Use:

    <!-- The region factory property is the "new" property (for Hibernate 3.3 and above) -->
    <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory">
    

    for instance creation, or

    <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory"/>
    

    to force Hibernate to use a singleton of Ehcache CacheManager.

    And then activate L2 caching and query caching:

    <property name="hibernate.cache.use_second_level_cache" value="true"/>
    <property name="hibernate.cache.use_query_cache" value="true"/>
    

    That’s for the Hibernate L2 cache setup.

    Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity?

    In theory, the @Cacheable is supposed to be a replacement for the Hibernate proprietary annotation and should be used in conjunction with the shared-cache-mode element:

    <persistence 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" version="2.0">
      <persistence-unit name="FooPu" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        ...
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <properties>
          ...
        </properties>
      </persistence-unit>
    </persistence>
    

    But as mentioned in this previous question, initial experimentation has not been successful (it might be related to HHH-5303, I can’t say, I didn’t investigate that much). So I suggest sticking with the proprietary annotations.

    References

    • Hibernate EntityManager reference guide
      • 2.2.1 Packaging
    • JPA 2.0 Specification
      • Section 3.7.1 “The shared-cache-mode Element”
      • Section 11.1.7 “Cacheable Annotation”

    Resources

    • Ehcache 2.0 supports new Hibernate 3.3 caching provider
    • Configure Ehcache as a Second Level Cache
    • Hibernate Second Level Cache

    Related question

    • How to use JPA2’s @Cacheable instead of Hibernate’s @Cache
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some threads saying this was doable, but did not find specific instructions
I found some classes designed for debugging in package com.sun.jdi like VirtualMachine , but
I found some really great code from Matt Gallagher for use with making Undo
I decompiled a source file and found some JVM instructions like JVM INSTR monitorenter
Reading through an old blog post on SAP's community network, I found some instructions
I've looked over the internet and found some instructions for this question: Using jQuery
I found some examples from Microsoft , but I'm not sure how to get
I followed the instructions found on the github page exactly. I would post some
I've been looking for a solution for this question. I found some information, but
I found some lovely websites - http://www.mini.jp/event_campaign/big-point/ , http://www.twenty8twelve.com/ and http://www.scozzese.com - all vertical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.