假设我有一个包含以下代码的映射:
@Type(
type = "commons.db.hibernate.GenericEnumUserType",
parameters = {
@Parameter(
name = "enumClass",
value = "commons.db.entity.Currency"),
@Parameter(
name = "identifierMethod",
value = "getValue"),
@Parameter(
name = "valueOfMethod",
value = "getByValue")
}
)
@Column(name="currency_id")
private Currency currency;
其中Currency是以下枚举:
public enum Currency {
FUN(0),
USD(1),
RUB(2),
UAH(3),
EUR(5);
private int value;
Currency (int value) {
this.value = value;
}
public String getName() {
return name();
}
public int getValue() {
return value;
}
public static Currency getByValue(int value) {
for (Currency currency : Currency.values()) {
if (value == currency.getValue()) {
return currency;
}
}
throw new IllegalArgumentException("Illegal value: " + value);
}
}
我无法理解这种用法的注意事项。这个实际上做了什么?