I like to persist a enum list type to a String. For example,
public enum Color {
BLACK,
WHITE,
YELLOW
}
public class MyEntity {
public List<Color> getColors();
}
For colors of BLACK and WHITE, it is persisted as string "BLACK,WHITE".
public class ColorListUserType implements UserType {
....
}
I have two questions:
1. how to tell Hibernate to use the ColorListUserType for the property "colors"?
2. how to write a query to search entities that has BLACK color?
From MyEntity e where Color.BLACK in e.colors
make sense?
Thanks very much for help.
Dave
|