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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:14:48+00:00 2026-06-09T01:14:48+00:00

The background to this question is the following: Hash code for expandable class (future

  • 0

The background to this question is the following:

Hash code for expandable class (future proof)

However, I should mention why I would like to know this.

I have a class with many roles (boolean fields). I don’t want to make named queries (JPA) like

@NamedQuery(name= "searchUserWithRoles", query="SELECT u FROM User u WHERE u.role.admin = :admin AND u.role.printer = :printer AND ... .. . .+ 20 more booleans...)

My idea was to make a hashcode (or similar) for all fields in the Role class which reduce the named query to:

@NamedQuery(name= "searchUserWithRoles", query="SELECT u FROM User u WHERE u.role.hashcode = :hashcode)

I think (but I am not sure) that this will increase the performance, but also make my queries very short (I have a more “Role” like fields in my user class).

Also, when I update the Role class with more roles fields I do not need to update the named queries.

So that is the background to the first question.

The new question is: Is there some way to generate a “hashcode like” field in the Role class that is a description of all fields that is true (even if the Role class is updated with more fields)?

Thanks in advance

  • 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-06-09T01:14:50+00:00Added an answer on June 9, 2026 at 1:14 am

    It sounds like you don’t need a “hash code” – you just need a bit mask. So long as you have 32 fields or fewer, you can store this in a 32-bit integer. If you have 64 fields or fewer, you can store this in a 64-bit integer.

    Each field would then have one bit dedicated to it – so admin could be bit 0 (value 1), printer could be bit 1 (value 2), then next field would be bit 2 (value 4) etc. Just add together the values (effectively a bitwise OR).

    Then to query for any particular combination, you’d just use a bitwise AND between the data and a “mask” with only the relevant bits set. So if you wanted to find every admin who didn’t have printer rights, you’d check for value & 3 == 1.

    Note that all of this may well interfere with any indexing the database would want to do, and the database may well optimize in this sort of way anyway. Do you have any evidence that storing them as separate fields – keeping your representation closer to your logical data structure – actually causes a problem?

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

Sidebar

Related Questions

Please refer to this background question. After constructing this COUNT, how would I then
See this question for the background. Basically, I have the following definition of a
For the background to this question, see How to I serialize a large graph
This question came to my mind when I learned C++ with a background of
Background I admit, this question stems from an ultimate lack of deep understanding of
This question is in regards to this blog entry. https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/ All the way at
This question is more UI/Design-ish than hard-core programming is. Background: I've been coding in
I'm coming largely from a c++ background, but I think this question applies to
Background (question further down) I've been Googling this back and forth reading RFCs and
This is probably a multi-part question. Background: we have a native (c++) library that

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.