Yes, you're right. Using @Enumerated you don't have to use an user type for saving an enumeration. But there are some caveats:
1) @Enumerated(EnumType.STRING)
Saving an enumeration as string is little waste of storage space and you tying your database to the name of the enumeration constant. Refactoring a constants name breaks existing data.
2) @Enumerated(EnumType.ORDINAL)
Saves an implementation detail of the enumeration. The ordinal of an enumeration constant is defined as its position in its enumeration declaration.
So changing the position of a constant will have catastrophic consequences.
Additionally there is a little waste of storage space, because an int will be used, whereas in most cases a tinyint is big enough.
I'm using always an user type (using java.sql.Types.TINYINT) to persist enumerations looking like this. So I keep full control of what is written to the storage.
Code:
public enum MyEnum {
FIRST((byte) 0),
SECOND((byte) 1);
private Byte value;
private MyEnum(byte value) {
this.value = value;
}
public Byte getValue() {
return value;
}
public static MyEnum fromValue(Object value) {
if (null == value || !(value instanceof Byte))
return null;
switch ((Byte) value) {
case 0:
return FIRST;
case 1:
return SECOND;
}
throw new IllegalArgumentException();
}
}