users@jpa-spec.java.net

[jpa-spec users] Converters and Enum

From: Michael Nascimento <misterm_at_gmail.com>
Date: Mon, 12 Mar 2012 23:46:23 -0300

Hi,

I have just joined the list, tried to search the archives for this,
but haven't found any message that address this directly.

So Linda asked about the case about Converters and inheritance. The
main use case would be enums.

For my current project, with a legacy database, I've created two
annotations: @PersistentId (with a int value) and @Acronym (with a
String value). I have an annotation processor that ensures each Enum
class is consistently annotated with only of them and that ids are
unique. Then I have a custom UserType (with Hibernate) to implements
the basic support in both cases (and a few helper classes, but that is
irrelevant).

The problem is while the mechanism is the same, I need to know the
target class in order to convert to and from the actual enum class. So
today I have to either parametrize my type for each class or creating
a subclass, the latter being the approach I've chosen. So I end up
with a single UserType subclass per enum and have to declare a type
for each of them.

Therefore, not only Converters would need to work based on the
inheritance chain, but also need to have access to the target mapped
class.

I can provide more information if needed.

Regards,
Michael Nascimento Santos
http://threeten.sf.net/