I'm implementing a solution in Java using Ebean and I'm having some issues choosing between using enum
s or simply look up tables.
I have a table "Tooth". A tooth can be "Temporary" or "Permanent".
I could create a simple enum
:
@EnumMapping(nameValuePairs = "TEMPORARY=T, PERMANENT=P")
public enum DentitionType { TEMPORARY, PERMANENT; }
However, if I want to do a direct SQL query, I have to convert "T" and "P", so a solution would be to use a lookup table as below:
@Entity
public class DentitionType {
@Column(length = 15)
public String name;
private static DentitionType permanent;
public boolean isTemporary() {
return !this.equals(getPermanent());
}
public boolean isPermanent() {
return this.equals(getPermanent());
}
public static DentitionType getPermanent() {
if (permanent == null) {
permanent = DentitionType.FIND.byId(2L);
}
return permanent;
}
}
This feels kind of hardcoded and for larger tables a lot of isSomething
functions are required.
Is there a better solution?