I feel a little dumb asking this but I can\'t find any simple answer to the question.
Take this simple entity as example:
@Entity
@Table( name=\"clienti\
You can map your enum
to a String
or to an ordinal number. Mapping to String
is the more portable approach as the mapping will survive changing the enumeration order.
Using your example:
@Entity
@Table( name="clienti" )
public class Cliente implements Serializable {
...
@Enumerated(EnumType.STRING)
private Gender gender;
...
}
The string mapping will use the simple name of the enumeration type, so you would have two possible values in the DB - 'Male' and 'Female'
public enum Gender { MALE, FEMALE }
The persistence provider takes care of the mapping, so in your code, you can continue using the Gender
enum and not worry about Strings or ordinals.