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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:12:53+00:00 2026-05-20T08:12:53+00:00

I have table containing a series of unique strings which I need to provide

  • 0

I have table containing a series of unique strings which I need to provide quick lookups to (besides for memory-caching).

@Entity
public class UniqueString {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Basic
    @NaturalId
    private String stringId;
}

Initially I had the stringId variable as @Id, however it turned out that some databases (e.g., oracle) went into full table scan when retrieving the object by string id; hence I switched to a long instead.

How can I quickly access the UniqueString object from a string stringId. I see two solutions so far:

  • Again, annotate stringId with @id and try to find a fix to why full table scans occur in some databases
  • Hash the string into a long (while loosing precision) and use a lookup table to return all objects matching the hash, then compare their stringId property for equality to find the match we’re looking for, e.g, :

.

LookupTable                    UniqueString
+----+------+                +----+----+----------+
|hid | hash |                | id |hid | stringId |
+----+------+                +----+----+----------+
| 1  |  123 | -------------> | .. | 1  |  ....    |
| 2  |  321 |        `-----> | .. | 1  |  ....    |
+----+------+                +----+----+----------+

Opinions, suggestions?

[EDIT] Ok I realize that my above table illustration could simply be normalized to

UniqueString
+----+-----+----------+
| id |hash | stringId |
+----+-----+----------+
| .. | 123 |  ....    |
| .. | 123 |  ....    |
| .. | 321 |  ....    |
+----+-----+----------+

This makes all the difference as I suspect both of the following queries would perform roughly the same:

  • from UniqueString where hash='123'
  • from UniqueString where stringId='abc'
  • 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-20T08:12:53+00:00Added an answer on May 20, 2026 at 8:12 am
    1. make sure there is an index on the stringId colum in the database

    2. just query the database using hql or criteria API

    3. configure your query cache to cache this kind query.

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

Sidebar

Related Questions

I have a table containing a series of names, events and dates. I've created
I have table containing information about a series of x number of quizzes. It
I have an R list containing a series of tables. Each table in the
I have a Table containing some information that I need. All these rows also
I have a table containing numbers, range between 1-1000 they are unique, but I
I have a database table containing fields RACE, ETHNICITY and ETH. I need to
I have a table containing a unique ID field. Another field (REF) contains a
I have a table containing IP Address,timestamp and browser columns.I need to find the
I have a table containing data which I do not want to wrap onto
I have a table containing user input which needs to be optimized. I have

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.