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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:05:56+00:00 2026-05-15T20:05:56+00:00

I have 2 tables : The table Data : id , plus many fields.

  • 0

I have 2 tables :

The table Data : id, plus many fields. Some of these fields are ‘codes’ which reference multilanguage values from the next table, for example country_code, continent_code.

The table Thesaurus which contains the multilanguage codes, with columns: code, code_type, language, text. Code is unique for one code_type but there might be the same code several times with different ‘code_type’ values.

Example data from this table :

code    code_type    language    text
----------------------------------------------------
USA     CNT          EN          United States
USA     CNT          FR          Etats-Unis
FR      CNT          EN          France
FR      CNT          FR          France
FR      LNG          EN          French
FR      LNG          FR          Français

So the country_code column of the data table might contain 'FR' or 'US', and the language code column might contain 'FR' as well. It is implicit that the country_code column contains a code of type 'CNT' for country, and the language_code column contains a code of type ‘LNG’ for language.

How can I map this in Hibernate so that I can do something like that in my Java code :
(let’s assume the current locale of the app is US English)

myData.getCountryCode(currentLocale.getlanguage()); --> returns 'France'
myData.getLanguageCode(currentLocale.getlanguage()); --> returns 'French'

Note that I can not modifiy the DB schema, which I didn’t design myself !

  • 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-15T20:05:56+00:00Added an answer on May 15, 2026 at 8:05 pm

    You can have list of two different POJOs, which are implementing same abstract class, in your Data class for both country code and language code (with fields code, language and text). To map them you can use “inheritance mapping” with single table strategy and define the code_type column as discriminator column.

        @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
        @DiscriminatorColumn(name = "code_type", discriminatorType = DiscriminatorType.STRING)
    

    You can then query the language code or the country code as follows

        myData.getCountryCode(currentLocale.getlanguage()).getText(); --> returns 'France'
        myData.getLanguageCode(currentLocale.getlanguage()).getText(); --> returns 'French'
    

    And you can define the code, code_type and language columns as unique.

    For more information see the hibernate “Mapping inheritance” section here

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

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Store the shared configuration in a plain text file, preferably… May 16, 2026 at 12:38 am
  • Editorial Team
    Editorial Team added an answer Here's the full schema as dumped by mysql: http://padm.us/schema Here's… May 16, 2026 at 12:37 am
  • Editorial Team
    Editorial Team added an answer Managed to sort this out! I had two frames in… May 16, 2026 at 12:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.