Monthly Archives: April 2009

What to do about enums in Hibernate/JPA/JPA2?

What to do about enums in Hibernate/JPA/JPA2? Print This Post

To ensure the integrity in data model and domain model enumerations are a necessity!

This is my statement and let me try to explain why I think it is important and what my solution to the problem is.

In the data model even that it is not read by the domain model it is a good idea to keep the data normalized. When this is said I must in the same sentence state than I am not into deep normalizing where data in the end is more obscure than useable – meaning not accessible. The most common example is that you have an entry table and for each entry you want a status or state. This could be a transaction table with a status that states if the transaction is new or processed. Instead of just adding the status as an integer [1, 2] or string [new, processed] is it good to have the relationship as a foreign key to a status table with to entries – [1, New] and [2, Processed]. With this construction you ensure the data integrity on the database level but this is NOT a good way to handle the data in the domain model.
Continue reading