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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:59:05+00:00 2026-05-20T05:59:05+00:00

I have lots of Java enums that I persist with Hibernate. As far as

  • 0

I have lots of Java enums that I persist with Hibernate. As far as I know there are two different standard ways to persist these enums:

@Enumerated(EnumType.ORDINAL)

This is the default, and it just persists the ordinal value from the enum.

@Enumerated(EnumType.STRING)

This persists the name of the enum value.

Those have worked fine for me so far, but now I have a new enum where I want to persist a custom value from the enum that is neither the ordinal nor the name. Is this possible? I searched around and saw lots of people asking how to persist the name, which is easily accomplished using EnumType.STRING, but I want to persist an int that can be used for comparison in my SQL queries. I tried overriding toString() to return my custom value, but that did not work.

I’ll paste my java enum below. I want to persist the int value member from the enum.

Thanks in advance!

public enum Permission {
    VIEW (4),
    CHANGE(6),
    FULL(7);

    private int value;

    Permission(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}
  • 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-20T05:59:06+00:00Added an answer on May 20, 2026 at 5:59 am

    Yes, I’m missing a JPA solution, too.

    Workaround:

      private int permissionValue;
      private transient Permission permission;
    

    Then convert in the getter/setter of permission.

    Maybe you also need to implement some lifecycle methods? (I’m not sure.)
    http://download.oracle.com/docs/cd/B32110_01/web.1013/b28221/undejbs003.htm#BABIAAGE

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

Sidebar

Related Questions

There are lots of java apps on my simulator menu screen which I have
I have trees in two different pages, both have lots of other functionality too.
I made an application that encrypts and stores files in JAVA. I have lots
I have Foo.java , which is interface. And lots of classes that implement it.
I have a Java 3D program which uses lots (hundreds) of 3D models (3ds
I have written a java program generates lots of files (say txt files) in
Like lots of askers on SO, I'm relatively new to java and have attempted
I have lots of directories filled with a bunch of TeX documents. So, there's
I have lots of tables with statistical data (environment related) and wondering if there
In our infrastructure, we have lots of little Java projects built by Maven2. Each

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.