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

  • Home
  • SEARCH
  • 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 3210766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:37:00+00:00 2026-05-17T14:37:00+00:00

I have few tables like Country,state city which has static data. User do not

  • 0

I have few tables like Country,state city which has static data. User do not enter any data in this data. I create pojo for Country, State, City. There are few pojo which has mapping with static data. My requirement is that whenever any request comes to Hibernate for Country (21), it do not hit database but return data from cache . Is this possible in Hibernate. I need few pointers and your views to implement caching in my project. I am using hibernate annotations.

  • 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-17T14:37:01+00:00Added an answer on May 17, 2026 at 2:37 pm

    My requirement is that whenever any request comes to Hibernate for Country (21), it do not hit database but return data from cache. Is this possible in Hibernate.

    Yes, this is possible using the Second Level Cache and this kind of Entities (read-only) are the perfect candidates for caching (they are the easiest to manage). You’ll need to:

    • enable the 2nd level cache
      • set the hibernate.cache.use_second_level_cache property to true in your configuration
    • choose a 2nd level cache provider (I suggest EHCache)
      • set the hibernate.cache.provider_class property accordingly
    • mark your entities as cacheable (using the read-only strategy)
      • Add @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) to your entities

    References

    • Hibernate Core Reference Guide
      • 3.4.4. Second-level and query cache
      • 19.2. The Second Level Cache
    • Hibernate Annotations 3.4 Reference Guide
      • 2.4.8. Cache

    More Resources

    • Hibernate: Truly Understanding the Second-Level and Query Caches
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database with few tables, ex.: Employee (Id, Name, state, country) Material
I have a few tables which I have joined together and would like to
I have a few tables with 70-80 columns in them. I would like to
I have a table with a few rows of data. I would like to
I have got a few tables which I am trying to join. I just
in my application I have a few CListCtrl tables. I fill/refresh them with data
I have a few tables that reference the same table. For example: Person has
I have a few different notification tables, and I would like to perform a
Say that I have a few tables that never change, such as a 'State'
I have a few tables in MySQL like so: A ---- A_has_B ---- B

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.