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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:02:33+00:00 2026-05-21T09:02:33+00:00

I have a model object that’s in fact an enum with fields and getters:

  • 0

I have a model object that’s in fact an enum with fields and getters:

@Entity
public enum Type {
   TYPE1, TYPE2, TYPE3, TYPE4;

   @Column
   private Long id;
   @Column
   private String name;
   ...

   public String getName() {
      return this.name;
   }
   ...
}

It compiles and runs fine. However, if I call a getter method, it returns null (it doesn’t load any values stored in the database). Is this the standard behavior? Is there a way to make JPA load them?

  • 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-21T09:02:33+00:00Added an answer on May 21, 2026 at 9:02 am

    I’d say there is some misconception in this aproach:

    1. Entities represent objects that can be stored in the database. In this case, the database (or any other persistent store) defines which instances are available.

    2. Enums represent a fixed set of constants that are defined in source code. Thus the class itself defines which constants are available. In addition, it’s generally bad practice to change the values of an enum, i.e. the name or id in your case.

    You see that they are two quite different concepts which should be treated differently.

    To store enums in entities (where the enum is a field of that entity), you could either use @Enumerated and store the name or ordinal of the enum, or (what we do more often) store one of the fields (we mostly use the id) and provide conversion methods.

    If you want to store configurable “constants” in the database you might try and use plain entities for that, make the constructor private (Hibernate and other JPA providers should be able to deal with that) and provide an alternative implementation of the Enum class (you can’t use the enum keyword though).

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

Sidebar

Related Questions

I have an object model that looks like this: public class MyObjectModel { public
I have an object model that looks like this: public MyObjectInJson { public long
I know that the asp.net repeater doesnt have a Client side object model, and
In my Core Data managed object model, I have an entity Foo with a
In my application, I have a model object that contains a collection lets say
I have a Rails model Object that does not have an ID column. It
I have an object model that contains a boolean MyBool and I have a
I have a Post model object that has reference to a parent object. The
I have a GeoDjango model object that I want't to serialize to json. I
Suppose I have an model object Event that contains a Venue . When I

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.