Is there any way to do something like this. I have an entity called person.
@Entity
@Table(name = "PERSON")
public class Person {
@Column(name = "NAME", length = 128, columnDefinition = "VARCHAR2(128)")
String name;
@Column(name = "NATIONALITY", length = 128, columnDefinition = "VARCHAR2(128)")
String nationality;
}
The 'NATIONALITY' column has numeric values - every number is a code of a country. I would like to map the 'nationality' field to my custom enum and create some method transforming code<->country.
@Entity
@Table(name = "PERSON")
public class Person {
@Column(name = "NAME", length = 128, columnDefinition = "VARCHAR2(128)")
String name;
@Column(name = "NATIONALITY", length = 128, columnDefinition = "VARCHAR2(128)")
Nationality nationality;
}
enum Nationality {
USA, Brazil, Germany; // etc.
}
public static Nationality codeToNationality(String code);
Is there any hibernate methods for something like this? I can't modify columns definitions - the database is read only.
The second thing I'd like to achieve is to exclude any entities of unresolved nationality codes. The entities of codeToNationality(...) == null would be invisible to hibernate.
My model (persons, nationalities) is only an example.
Thanks for any help!