我正在尝试使用休眠将一组枚举存储到数据库中。
枚举类似于
public enum SomeEnum {
ITEM,
ITEM2,
}
我有一个像这样的休眠模型实体
@Entity
public class TableObject implements BaseObject {
private Long id;
private Set<SomeEnum> someEnumSet;
@Column(name = "TABLE_COLUMN", nullable = true, insertable = true, updatable = true)
@ElementCollection
public Set<SomeEnum> getSectionSet() {
return sectionSet;
}
public void setSectionSet(Set<SomeEnum> sectionSet) {
this.sectionSet = sectionSet;
}
}
而且我认为@ElementCollection注释不正确。"TABLE_COLUMN"列在数据库中属于 CLOB 类型。(甲骨文)。
谢谢亚历克斯。
尝试添加@Enumerated注释:
@Entity
public class TableObject implements BaseObject {
private Long id;
private Set<SomeEnum> someEnumSet;
@Column(name = "TABLE_COLUMN", nullable = true, insertable = true, updatable = true)
@ElementCollection
@Enumerated(EnumType.STRING)
public Set<SomeEnum> getSectionSet() {
return sectionSet;
}
public void setSectionSet(Set<SomeEnum> sectionSet) {
this.sectionSet = sectionSet;
}
}
它应该使休眠状态以将您的枚举存储为字符串(枚举名称)