Hibernate save Set <Enum> to the database

I am trying to save a set of enumerations to a database using sleep mode.

The listing is similar to

public enum SomeEnum { ITEM, ITEM2, } 

And I have a Hibernate model model 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 the @ElementCollection annotation is correct. The column "TABLE_COLUMN" is of type CLOB in the database. (Oracle).

Thanks, Alex.

+6
source share
1 answer

Try adding the added @ 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; } } 

This should make hibernation to store your names as strings (name names)

+5
source

All Articles