hibernate store a Set<Enum> into database

enums, hibernate, java, spring

Solution

Try to add @Enumerated annotation:

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

It should make hibernate to store your enumes as a Strings (enumes names)

Problem

I'm trying to store a Set of enums into database using hibernate. The enum is something like ``` public enum SomeEnum { ITEM, ITEM2, } ``` And I have a Hibernate model entity like this ``` @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; } } ``` And I don't think @ElementCollection annotation is correct. 'TABLE_COLUMN' column is of type CLOB in the DB. (Oracle). Thanks, Alex.

Original source

Related problems