users@jpa-spec.java.net

[jpa-spec users] Re: Converters and Enum

From: michael keith <michael.keith_at_oracle.com>
Date: Wed, 14 Mar 2012 13:28:55 -0400

My first question would be to ask why you can't use Bean Validation for
some of this. Emmanuel would probably be interested in finding out more
about your use case and what kinds of things validation might need to
add to accommodate it :-)

Not sure if I understand your scenario, but I took away from it that you
will either need to have access to the mapped class in which the
converted attribute resides, or be able to override the converter for a
given type to be different for the subtypes. Not sure if that is close,
but maybe some code snippets would help...

-Mike

On 12/03/2012 10:46 PM, Michael Nascimento wrote:
> 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/
>