I am trying to use an enum as mapkey for a map in Hibernate, but Hibernate saves my enum as RAW:
I have this listing:
public enum AccountType implements Serializable {
CASH,
CREDIT_CARD,
GIRO,
INVOICE,
OTHER;
}
What I'm trying to use as a key on a map:
@CollectionOfElements
@MapKey(columns = @Column(name="ACC_TYPE"),
targetElement = AccountType.class)
@Column(name="ACCOUNT_NO")
public Map<AccountType, String> getAccounts() {
return accountMap;
}
What happens is that Hibernate stores the enumeration as raw in the database instead of varchar:
"Column Name" "Data Type"
"COMPANY_ID" "NUMBER(19,0)"
"ACC_TYPE" "RAW"
"ACCOUNT_NO" "VARCHAR2(255 CHAR)"
I want this to be saved as varchar. I tried adding @Enumerated (value = EnumType.STRING), but it doesn't seem to work on mapkey.
source
share