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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:06:30+00:00 2026-05-14T03:06:30+00:00

I have an enum type on my Java model which I’d like to map

  • 0

I have an enum type on my Java model which I’d like to map to a table on the database. I’m working with Hibernate Annotations and I don’t know how to do that. Since the answers I search were rather old, I wonder which way is the best?

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-05-14T03:06:30+00:00Added an answer on May 14, 2026 at 3:06 am

    Do you need something else than the @Enumerated annotation? For example, the following enum:

    public enum MyEnum { 
        VALUE1, VALUE2; 
    }  
    

    Could be used and annotated like this:

    private MyEnum myEnum;
    @Column(name="myenum") 
    @Enumerated(EnumType.ORDINAL) 
    public MyEnum getMyEnum() { 
        return myEnum 
    }
    

    You can specify how the enum should be persisted in the database with the EnumType enum property of the @Enumerated annotation. EnumType.ORDINAL specifies that the enum will be persisted as an integer value. Here, myEnum set to VALUE1 would be persisted as 0, VALUE2 as 1, etc.

    The alternative is to use EnumType.STRING to specify that the enum will be persisted using the name of the enum value that the field is set to. So, applied to the previous example, setting the field myEnum to MyEnum.VALUE1 will persist as VALUE1, etc.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First thing to look at is Oracle Advanced Replication and… May 16, 2026 at 4:04 pm
  • Editorial Team
    Editorial Team added an answer I like objdump for this, but the most useful options… May 16, 2026 at 4:04 pm
  • Editorial Team
    Editorial Team added an answer What if you do this: somecolumnname = ? instead of… May 16, 2026 at 4:04 pm

Trending Tags

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

Top Members

Related Questions

I have a Java Enum: public enum Equipment { Hood, Blinkers, ToungTie, CheekPieces, Visor,
Hi I have a Java enum and I want serialize a variable containing an
Does Java have the possibility of anonymous enums? For example, I want my class
I have a situation where I need the Checker enum below used in multiple
I have a problem with overriding the equals method in an Enum to make
So, maybe this is a bad design; I don't know. But say I have
I have a class Foo with a field UpdateMe of type Confirmation as described
Say I have a method declaration like: private void someMethod(final String someKey, final Object
I am dealing with the following scenario: We use table-per-subclass inheritance , meaning the
Is there a convention for naming enumerations in Java? My preference is that an

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.