I've got a model object that's actually an enum with fields and getters:

public enum Type {

   private Long id;
   private String name;

   public String getName() {
      return this.name;

It compiles and runs fine. However, basically call a getter method, it returns null (it does not load any values saved within the database). Is the conventional behavior? It is possible to method to make JPA load them?

I'd say there's some misunderstanding within this aproach:

  1. Organizations represent objects that may be saved within the database. Within this situation, the database (or other persistent store) defines which instances can be found.

  2. Enums represent a set group of constants which are defined in source code. Thus the course itself defines which constants can be found. Additionally, it's generally bad practice to alter the values of the enum, i.e. the title or id inside your situation.

The thing is that they're two quite different concepts that ought to be treated in a different way.

To keep enums in organizations (in which the enum is really a area of this entity), you can either use @Enumerated and keep title or ordinal from the enum, or (what we should do more frequently) store among the fields (we mostly make use of the id) and supply conversion techniques.

If you wish to store configurable "constants" within the database you could try and employ plain organizations for your, result in the constructor private (Hibernate along with other JPA companies should have the ability to cope with that) and supply an alternate implementation from the Enum class (you cannot make use of the enum keyword though).

Perhaps you have investigated the @Enumerated annotation? I've not ever attempted for doing things inside an enum itself, nevertheless it works quit well binding a category property for an enum.

enum Type{TYPE1, TYPE2}

public Type getType(){return type;}
public void setType(Type t){type = t;}

If JPA can't be made additional, you could include a public Type valueOf(long id) approach to your enum class that you simply use like a factory to instantiate enum instances representing the values inside your legacy table.