xenoterracide
xenoterracide

Reputation: 16865

MapKeyEnumerated to String

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "entity_identifier")
@MapKeyEnumerated(EnumType.STRING)
@MapKey(name = "type")
@Column(name = "identifier")
val identifiers: MutableMap<IdentifierType, String> = mutableMapOf()

throws this

Caused by: org.hibernate.AnnotationException: Associated class not found: java.lang.String

the tables are simple

create table entity(
    id serial primary key
);
create table entity_identifier(
    entity_id bigint references entity ( id ),
    identifier text,
    type text,
);

is there a way I can make this Map work?

Upvotes: 2

Views: 783

Answers (1)

xenoterracide
xenoterracide

Reputation: 16865

It looks like I need to use @MapKeyColumn, I don't know why

@ElementCollection( fetch = FetchType.EAGER)
@CollectionTable(name="entity_identifier")
@MapKeyColumn(name="type")
@MapKeyEnumerated(EnumType.STRING)
@Column(name = "identifier")
val identifiers: MutableMap<IdentifierType, String> = mutableMapOf()

Upvotes: 2

Related Questions