I think it's often common to find database enumeration tables which translate the meanings of column codes. For example, you might have a status field in a User table
Code:
CREATE TABLE User (
id INTEGER,
status TINYINT,
name VARCHAR
email VARCHAR
....
)
Which is translated by another table UserStatus
Code:
CREATE TABLE UserStatus (
id TINYINT,
name CHAR(10) ,
created DATETIME
)
I have read the section in
Hibernate in Action on enumerated types, which suggests that a Serializable class in our domain model, say com.acme.model.UserStatus and also an accompanying implementation of UserType could be used to model this sort of enumeration. I take it that this would mean that the domain class would not really know about the UserStatus table per se. If we added a new status to our system, we would have to update our UserStatus class accordingly.
This is all well and good except what should I do if i want to furthermore treat the UserStatus table in the physical as an (immutable) entity type which I can query with greater complexity? (E.g. finding all the status fields that were created before a certain date?) Would I create an entirely different domain class and create another hbm.xml file?
Or is there a more elegant solution?