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 5950387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:11+00:00 2026-05-22T17:23:11+00:00

Hi in my application i have few small tables and i cache them All

  • 0

Hi in my application i have few small tables and i cache them All at the server startup in a Map. I want to implement same functionality by Ecache + hibernate combination

my class looks like

  @Entity
  @Table(name = "Order")
  @NamedQueries
  ({
     @NamedQuery(name="Order.findBySource", 
        query="from Order a where a.source = :source"),

     @NamedQuery(name="Order.findByAll", 
        query="from Order"),

     @NamedQuery(name="Order.findByPrioritySource", 
        query="from Order a where a.priority = :priority and a.source =   :source"),

     @NamedQuery(name="Order.findByPriority", 
        query="from Order a where a.priority = :priority"),

     @NamedQuery(name="Order.findByWhenModified", 
        query="from Order a where a.whenModified = :whenModified")
     })
      @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

    public class Order implements java.io.Serializable {

      private String source;
      private long priority;
      private Date whenModified;
    }

this order table has hardly 10 entries and i want to keep this table in memory all the time.
any insights how can i achieve this?

i fire the above named queries to fetch the orders. I do not want to go to DB again and again when i fire this query so for this in ecache.xml do i need to make an entry of this class ? or i need to cache these Named queries in ecache.xml?

is it possible to replicate the Map implementaion by Ehcache. so that i can get the object just by specifying the ID from the cache without hitting the DB again and again ?

  • 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-22T17:23:12+00:00Added an answer on May 22, 2026 at 5:23 pm

    The thing you need is Hibernate query cache. First of all you need to enable it on Hibernate level by setting hibernate.cache.use_query_cache property to true. Then when you execute your query in the code you need to set a flag on the query object to indicate that it requires caching:

    Query q = session.getNamedQuery("Order.findByPriority");
    q.setCacheable(true);
    List result = q.list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my application I have a few CListCtrl tables. I fill/refresh them with data
I am developing a small application in android in which i have few image
I have written a small perl application for deployment on a few servers. It
I have just started programming and have made a few small applications in C
I am writing an application, where I do have few different windows implemented, where
I am using Ext.Net 1.3 with ASP.NET 4.0 application. I have few Ext ComboBox
I have a few JAVA application that I monitor using JMX. I would like
I'm creating a Windows Console application written in VB.NET and I have a few
I'm currently using Look&Feel for my application. I have a few problems: 1. When
If I have an application with only a few event handlers registered (and the

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.