We've got a situation where we'd like to be able to natively persist Enum objects to the DB so I'm very interested to hear when it'll be available.
We've got about 250 tables of which about 50 are purely lookup type values. For ease of programmability we'd like those lookup tables to be managed via Enums. Most contain 3 fields (per value) but some are much more involved with nested Enums etc.
e.g.
Code:
public enum Blah {
FOO( 1, "Foo", "This is a foo", Colour.SILVER),
BAR( 2, "Bar", "This is a bar", Colour.GOLD);
private Integer id;
private String value;
private String description;
private Colour colour;
Blah(Integer id, String value, String description, Colour colour) {
this.id = id;
this.value = value;
this.description = description;
this.colour = colour;
}
public Integer getId() { return id; }
public String getValue() { return value; }
public String getDescription() { return value; }
public Colour getColour() { return colour; }
}
By exposing the fields with getter methods it is possible to persist like any other class however it fails on the retrieve with a "no default constructor" error. If it is possible to "plugin" a new constructor e.g. based on an approach similar to the nullSafeGet(s) on
http://www.hibernate.org/272.html then please let me know.
Is there any other way to use Enums to represent DB tables and participate in all mappings (property, one-to-one, one-to-many, many-to-many, many-to-one)?