Problem
With no SQL enumeration type, unfortunately, the somewhat popular database design pattern seems to create one table for all enumeration values (thanks for the link, Nathan). I have seen many variations of this over the years, but the one I am facing right now looks something like this:
ID | ENUM | VALUE -----+-------------+---------- 1 | DAY_OF_WEEK | SUNDAY 2 | DAY_OF_WEEK | MONDAY ... 7 | DAY_OF_WEEK | SATURDAY ... 18 | PERSON_TYPE | EMPLOYEE 19 | PERSON_TYPE | MANAGER
which is then used like this - for example, in the face table:
ID | NAME | TYPE ----+----------+------ 1 | Jane Doe | 19
Meaning that Jane is a manger, because 19 is the primary key of personalization of the manager type in the enumeration table.
Question
Using JPA (2.1), is there an elegant way to map this construct to Java propper Java?
Important: There are many versions of my "enum" table in different versions with different primary key values, that is, the "manager" can sometimes be line # 19, but sometimes line No. 231. However, the values ββnever change at run time. Unfortunately, changing the database schema is also not an option, but using the proprietary features of any JPA provider will be an option.
What worked
I really found a solution that worked, but it was too bad for me:
public enum PersonType { EMPLOYEE, MANAGER } @Table(name="PERSONS") @Entity public class Persons { @Id @Column(name="ID") long id; @Column(name="NAME") String name; @Convert(converter = PtConv.class) @Column(name="TYPE") PersonType type;
I would live with this if CDI were available in @Converter , but with a static construct was a nightmare.