hibernate - MapKey枚举为字符串

标签 hibernate jpa hibernate-5.x

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

抛出这个

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

表格很简单

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

有什么办法可以让这个Map工作吗?

最佳答案

看起来我需要使用@MapKeyColumn,我不知道为什么

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

关于hibernate - MapKey枚举为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57798919/

相关文章:

java - Spring @Retryable 与有状态的 Hibernate 对象

mysql - 未调用 C3P0 连接池测试器

java - Hibernate 生成预定义的实体标识符

java - Hibernate 检查注解

java - 带有前缀的JPA多个嵌入式字段?

Hibernate 5 隐式命名策略

java - 使用更改监听器 javafx 仅选择 TreeView 的子项目(树项目)

java - 在 jpql select 中指定列会导致转换错误

java - 事件监听器 hibernate 5

Hibernate 更新、PropertyAccessor、ChainedPropertyAccessor、PropertyAccessorFactory 在版本 5.3.7 中不再可用