I'm trying to create an entity where one of the field is a Map with Enum key:
public class MyEntity {
@ElementCollection
@CollectionTable(name="attributes", joinColumns=@JoinColumn(name="my_entity_id"))
@MapKeyColumn(name = "attribute_key")
@Column(name="attribute_value")
private Map<Attribute, String> attributes;
}
The Attribute
is just a simple enumeration with no additional fields or logic:
public enum Attribute {
ATTRIBUTE1, ATTRIBUTE2, ATTRIBUTE3;
}
This maps nicely and do work. But the collection table, attributes
creates with integer
column definition for my map key, as the default is EnumType.ORDINAL
. For my purposes I need it to be string, but I can't just place @Enumerated(EnumType.STRING)
on my field as this leads to an exception.
Do I have any options of how can I achieve this desired behaviour? Thanks very much.