I need to map the enums which didn't implement the interface beforehand to the existing database, which stores enums in the same table as the owner class using the @Enumerated(EnumType.STRING)
.
class A {
HasName name;
}
interface HasName {
String getName();
}
enum X implements HasName {
John, Mary;
public String getName() { return this.name(); }
}
enum Y implements HasName {
Tom, Ann;
public String getName() { return this.name(); }
}
How the mapping should be handled in this case? Persisting to the database doesn't change as all of the enums implementing the interface will have different values, but I'm not sure how the objects should be retrieved from the DB (do I need a custom mapper, which will try to instantiate an enum using the specified enum classes? Does Hibernate natively support this functionality?).