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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:59:26+00:00 2026-05-18T02:59:26+00:00

I have a user object represented in JPA which has specific sub-types. Eg, think

  • 0

I have a user object represented in JPA which has specific sub-types. Eg, think of User and then a subclass Admin, and another subclass Power User.

Let’s say I have 100k users. I have successfully implemented the second level cache using Ehcache in order to increase performance and have validated that it’s working.
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-cache

I know it does work (ie, you load the object from the cache rather than invoke an sql query) when you call the load method. I’ve verified this via logging at the hibernate level and also verifying that it’s quicker.

However, I actually want to select a subset of all the users…for example, let’s say I want to do a count of how many Power Users there are.

Furthermore, my users have an associated ZipCode object…the ZipCode objects are also second level cached…what I’d like to do is actually be able to ask queries like…how many Power Users do i have in New York state…

However, my question is…how do i write a query to do this that will hit the second level cache and not the database. Note that my second level cache is configured to be read/write…so as new users are added to the system they should automatically be added to the cache…also…note that I have investigated the Query cache briefly but I’m not sure it’s applicable as this is for queries that are run multiple times…my problem is more a case of…the data should be in the second level cache anyway so what do I have to do so that the database doesn’t get hit when I write my query.

cheers,
Brian

  • 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-18T02:59:26+00:00Added an answer on May 18, 2026 at 2:59 am

    (…) the data should be in the second level cache anyway so what do I have to do so that the database doesn’t get hit when I write my query.

    If the entities returned by your query are cached, have a look at Query#iterate(). This will trigger a first query to retrieve a list of IDs and then subsequent queries for each ID… that would hit the L2 cache.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
When creating a web application, and lets say you have a User object denoting
I have a function that loads a user object from a web service asynchronously.
I have a NSTimer object that I need to invalidate if a user taps
I have a program in which the user adds multiple objects to a scene.
I have an array of objects which populate a UITableView . When a user
I have a user interface in .net which needs to receive data from a
I have a WPF window for editing database information, which is represented using an
In my WPF project I have a custom control which is visually represented by
I have a custom UI control which has a JavaScript class written around 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.