> -----Original Message----- > From: KARR, DAVID (ATTSI) > Sent: Friday, June 04, 2010 9:20 AM > To: [email protected] > Subject: Issues mapping int column to generic enum, where column value > is not enum ordinal > > 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?
If it matters, I was able to get this to work. There are always little details that have to be right, and I was missing some of them, but the basic idea works fine. In my EnumColumnValueHandler, the Map keys are the "getColumnValue()" values, not the ordinal values. I also have to have each cooperating enum type implement a "EnumColumnValue" interface.
