Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 休眠存储一套<;Enum>;进入数据库_Java_Spring_Hibernate_Enums - Fatal编程技术网

Java 休眠存储一套<;Enum>;进入数据库

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

我正在尝试使用hibernate将一组枚举存储到数据库中

枚举类似于

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将枚举存储为字符串(枚举名称)