ORM – object relation mapping

Team is encountering an exception, “unknown enum value for (some enum class) : (some enum constant name)” kind of exception.

I have been keep debugging, following the stack trace for half a day. And since the stack trace goes so deep, my eclipse crash many times.

This is another reason why I hate persistence, and prefer mybatis.

We should have a control of how we store our object, and what kind of data we wanna retrieve from database. We can decide what’s the update, insert and queries. Instead of leaving to jpa, or hibernate, which might forever won’t be able to be perfect. As they are trying to suit for all kinds of objects.

The exception we encountered, is during the process of retrieving the data. We are trying to get an message object. Then this message object actually linked to an exception object, by the foreign key, exceptionid. Then inside this exception object, there is one property which is an enum type. And this exception again maps to an exception table. (I hate this kind of object, table links, again. And there are too many restrictions in order to make the forever not perfect orm work.)

When retrieving the exception object, the not so famous exception, “unknown enum value for ..” occurred. We have annotated the property as enumerated, and the type as string. And i have tested, enum.valueof(enum lass, enum const name), returns correct. Somewhere, the jpa, hibernate, plus the enumerated annotation breaks down. Probably they need some more restricted setting to tell them, what map to what, and how. Shit.

At the sad time, for debugging process, I have made another conclusion, based on this time experience. I am always stubborn as trying to follow the sequence, follow the order, from beginning to end, wanna know all details, which doesn’t work in some scenarios, and especially during process of debugging such deep stack trace.

Follow the exception, trace reverse should be better solution. put a break point at the exception.

Trace in reverse order!


It turns out, it is not the problem of jpa or hibernate. Instead, it’s the database column type problem. The column is using char 12. So even though enum constant name is stp, only 3 character. However, once put into database, and later wanna retrieve this column, it retrieves as char12, with 9 spaces trailing stp.

Enum.value of(enum class, enum constant name), which us used by hibernate to persist out the data as the enumeration constant, can’t find the enum constant as such.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s