openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Issues mapping int column to generic enum, where column value is not enum ordinal
Date Fri, 04 Jun 2010 16:19:52 GMT
Using OpenJPA 1.2.2.

I'm still struggling with how I can effectively map integer columns to
an enum type.  It's easy enough when the type is used for only a single
column, as I just define a value handler for my strategy.  It would also
probably be easy if my column values corresponded to the ordinals of the
enum values.  This is not the case.

I designed my enum type so the corresponding column value is specified
in the constructor.  I also defined a "EnumColumnValue" interface that
my enum type implements that defines the "getColumnValue()" method.  I
also defined a "EnumColumnValueHandler" to use as the strategy, which
knows about the column values.  This seems sound so far, although I
haven't been able to get this to execute yet.

My problem right now happens when I try to build and execute a query
that looks for a particular enum value. When I specify the enum value as
a parameter, what gets put into the SQL is the ORDINAL of the enum
value, so it looks for the wrong value.  I tried setting the parameter
using the "getColumnValue()" method of the EnumColumnValue, but that
fails, as it expects a value of the enum type, not integer.

How can I make the generated SQL use the supplied column value of the
EnumColumnValue, instead of the ordinal value?

Am I going to have to make some compromises to get this to work?

View raw message