Java 休眠存储一套<;Enum>;进入数据库
我正在尝试使用hibernate将一组枚举存储到数据库中 枚举类似于Java 休眠存储一套<;Enum>;进入数据库,java,spring,hibernate,enums,Java,Spring,Hibernate,Enums,我正在尝试使用hibernate将一组枚举存储到数据库中 枚举类似于 public enum SomeEnum { ITEM, ITEM2, } 我有一个像这样的Hibernate模型实体 @Entity public class TableObject implements BaseObject { private Long id; private Set<SomeEnum> someEnumSet; @Column(name = "TABLE_COLUMN
public enum SomeEnum {
ITEM,
ITEM2,
}
我有一个像这样的Hibernate模型实体
@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;
}
}
@实体
公共类TableObject实现BaseObject{
私人长id;
私有集;
@列(name=“TABLE_Column”,nullable=true,insertable=true,updateable=true)
@元素集合
公共集getSectionSet(){
返回段集;
}
公共无效集合区段集(集合区段集){
this.sectionSet=sectionSet;
}
}
我认为@ElementCollection注释不正确。
“TABLE_COLUMN”列在数据库中为CLOB类型。(甲骨文)
谢谢,
Alex.尝试添加@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;
}
}
@实体
公共类TableObject实现BaseObject{
私人长id;
私有集;
@列(name=“TABLE_Column”,nullable=true,insertable=true,updateable=true)
@元素集合
@枚举(EnumType.STRING)
公共集getSectionSet(){
返回段集;
}
公共无效集合区段集(集合区段集){
this.sectionSet=sectionSet;
}
}
它应该使hibernate将枚举存储为字符串(枚举名称)