Enum and Hibernate Mismatch?
Hibernate nicely supports enum ordinal type and string type out of the box as defined in the Java Persistence API (JPA) specification. But, sometimes with legacy databases you need custom enum mapping.
There is lot of information out there, but the following are the two most useful:
So much meta information is specified for a simple enum in the above links. Wow! Something just doesn’t feel right about it. If I default / hardcode the identifierMethod and valueOfMethod, I can get it look like the following:
1: @Column(name = "ORDER_TYPE")
2: @Type(type = "ms.EnumUserType",
3: parameters = {@Parameter(name = "enumClass", value = "ms.domain.Order$OrderType")})
4: private OrderType mOrderType;
Still, I am specifying redundant information in value because I should be able to figure that out by the declared type of the member variable OrderType in this case.

Pretty insightful post. Never thought that it was this simple after all. I had spent a good deal of my time looking for someone to explain this subject clearly and you’re the only one that ever did that. Kudos to you! Keep it up
Reply to this