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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:27:12+00:00 2026-06-01T04:27:12+00:00

Hi am modelling an Entity with a column named Gender. In the application code,

  • 0

Hi am modelling an Entity with a column named “Gender”. In the application code, the gender is supposed to be an (Java) Enum type, with 2 values (MALE and FEMALE).. how would you model it, knowing that Enums as Datatype are not part of the generic SQL (language) 92.

It the data model would have to be portable, in order to be used by several DBMS (Mysql, Oracle, Derby) and several persistence provider (JPA, Hibernate, JDBC).
I feel, it hits at 2 levels:
– first the level of the Schema and the entity (store the enums as -VAR-CHAR or INT)
– second the level of the app code (JDBC doesn’t support enums, JPA does but it depends on the implementation)

Is there a generic solution, applicable for example to an Mysql DBMS ?
Thanks !!

  • 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-01T04:27:13+00:00Added an answer on June 1, 2026 at 4:27 am

    I typically adopt the following solution, which gives a fully normalised database schema.

    1. Create a dedicated table to represent your enumeration; e.g. Colour. The table will have two columns:
      • An ID column (primary key). Typically an auto-incrementing int, smallint or tinyint.
      • A name column (candidate key). This will be a varchar whose value should be identical to the Java enumeration.
    2. Create a Java enum: Colour with identical values to the Colour table in the database.
    3. Assuming you now have a “Data” table containing records that reference the Colour table, implement a stored procedure for inserting a record, which takes the Colour String value (as described by your Java enum); e.g.

      CREATE PROCEDURE dbo.InsertRecord
      @colour varchar(32)
      AS
      …

    The stored procedure will perform the necessary String-to-int translation allowing your data table to reference a the Colour table via an int foreign key.

    Similarly you can create a view onto your data table(s) that will join to the Colour table behind the scenes to present a denormalised via of your data back to the application or end user.

    The alternative to the stored procedure approach is that you read and cache the ordinal, name mappings within your application on startup. This has the advantage of being able to verify the integrity of your Java Colour enum compared with the contents of your Colour table in the database.

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

Sidebar

Related Questions

I am working on a web application (C#, VS2008 with Entity modelling) and will
I am modelling the domain model in my application. Obviously, some of the object
I am developing a geneaology application, and am currently at the stage of modelling
I have c# application which writes files to an sqlite database. It uses entity
I am modelling a database for use in a sql only application for now.
How would one structure a table for an entity that can have a one
I'm pretty new to the Entity framework and I'm modelling this simple structure: With
I have some basic knowledge of Entity Framework 4.1 Code First, but haven't used
I'm modelling a database and I want to ask about the Varchar type. Is
One of my entity classes would be possible to store in a sql server

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.