EnumMap的Hibernate注释<enum,string>(OneToMany)</enum,string>

时间:2013-11-13 13:35:19

标签: java hibernate enums annotations enum-map

我很难找到bean属性的正确hibernate注释。 这是一个EnumMap变量。 K是EnumType,K是String。我看到许多帖子讨论类似的主题,但我没有看到任何线程,他们使用String作为地图值。我猜这可能是问题所在。我想将它映射为OneToMany关系。如果EnumMap的键值是表中的字符串值并且映射应该可以为空,那就太好了。 那可能吗?我试过这个:

@OneToMany
@MapKeyEnumerated(EnumType.STRING)
private EnumMap<IDType, String> ids;

和枚举的注释但没有任何作用。我得到一个例外:

Initial SessionFactory creation failed.org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: entities.persistent.IDContainer.ids

对任何想法都会非常高兴。我有点失落...... 非常感谢!

1 个答案:

答案 0 :(得分:0)

您可以使用@ElementCollection批注:

@ElementCollection
@MapKeyEnumerated(EnumType.STRING)
private Map<IDType, String> ids = new EnumMap<>(IDType.class);