I’ve a Color Enum
public enum color { GREEN, WHITE, RED }
and I have MyEntity that contains it.
public class MyEntity {
private Set<Color> colors;
...
I already have a UserType to map my Enums.
Do you know how to map a Set of Enums in the Hibernate hbm.xml?
Do I need a UserType or there’s an easiest way?
Thanks
edit: Just to remark, I’m looking for the hbm.xml configuration not the @CollectionOfElements Annotation
I use the solution from the EnumSet mapping thread which relies on the use of
<element column>. You just need a table with an id and a string to map the collection (MYENTITY_COLORhere). And the mapping looks like that (theEnumUserTypeis the one from Java 5 EnumUserType):Query might look like this:
The whole solution works well for loads, saves and queries (credits to jasonab).