Mateusz Mańka
Mateusz Mańka

Reputation: 858

Hibernate how to map Enum key and value in Map<enum,enum> as a String

How can i map enums as string to database in Map in Hibernate I now how to map key with @MapKeyEnumerated, but how to do the same with value of my map ?

Part of Model code :

@MapKeyClass(value = Allergen.class)
@MapKeyEnumerated(value = EnumType.STRING)
@ElementCollection(targetClass = AllergicStatus.class)
private Map<Allergen,AllergicStatus> allergens;

Where Allergen and AllergicStatus is enum

Upvotes: 5

Views: 1384

Answers (1)

Mateusz Mańka
Mateusz Mańka

Reputation: 858

Answer for my own question is @Enumerated(EnumType.STRING)

@MapKeyClass(value = Allergen.class)
@MapKeyEnumerated(value = EnumType.STRING)
@ElementCollection(targetClass = AllergicStatus.class)
@Enumerated(value = EnumType.STRING)
private Map<Allergen,AllergicStatus> allergens;

Upvotes: 6

Related Questions