10

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;
}
}

そして、@ElementCollectionアノテーションは正しくないと思います。'TABLE_COLUMN'列は、DB内のタイプCLOBです。(Oracle)。

ありがとう、アレックス。

4

1 に答える 1

8

@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;
   }
}

列挙型を文字列 (列挙型名) として保存するには、休止状態にする必要があります。

于 2012-11-22T16:40:15.913 に答える