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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With