I have two tables: the primary table, Order, and the other table, Status. Order has a foreign key, status_id. Status is a table of the following Strings: “Complete”, “In transit”, or “Pending”. Am I right in saying that what I would usually implement is two entities, Order and Status, where the Order entity has a Many-to-one mapping for the foreign key? The reason I think it would be a many to one mapping is because each Order only has one Status, but the Status values will obviously be reused (e.g., a bunch of different Orders could have a status of “In transit”).
However, I have one additional question. Since the “Status” table is going to be a simple table with only one String column, and only with 3 rows, is there an easier way to implement it in Hibernate? Does it actually have to be an entity or is there some value based mapping I can use?
Also, please make any examples mapping based (XML)… I am using hibernate mapping files, not annotations or anything else.
If your status table is only strings, I would suggest you collapse your status_id to a character column in your order table and use a Enum to encode the various statuses. You can add an extra getter method to return the Enum instead of the status. In your enum class, you can have the descriptive strings and you can have them as nouns, verbs etc.
Here is an example enum template I use in Eclipse for this purpose: