Using an enumeration as mapkey results in RAW in the database

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.

+3
source share
2 answers

Hibernate UserType . db DDL.

. https://www.hibernate.org/265.html

+1

@MapKeyEnumerated JPA, Hibernate core 3.6.5 , , , DDL. raw: (

0

Source: https://habr.com/ru/post/1705335/


All Articles