Patrick Linskey on 03/01/08 06:54, wrote:
I see that I can configure my mappings to use either EnumType.ORDINAL or STRING and I'm a little concerned that this is slightly restrictive, since the use of ORDINAL more or less compels me to keep my database data inline with my code, which may not be possible.Is this configuration option part of the EJB3 standard?The JPA 1 spec only discusses ordinal- and string-based options. In the past, we have discussed something similar to OpenJPA's externalization features for inclusion in a future JPA release; this could let you move the code for specifying the DB value out of the enum altogether and essentially into mapping data. I believe that it would be possible to use OpenJPA's externalization features on an enum field currently, although I'm not sure if we have any test suites for that configuration.
So the externalization feature would essentially map the DB value to the Enum ordinal?
I think it would be disadvantageous to adopt custom OpenJPA features unless theywere likely to be included in the spec in the future. A value-based strategy for Enums is a must-have for use on projects with existing databases. With those 2 points in mind, its absence more or less pushes you back to using public final statics.
Also, I have been searching the OpenJPA code base to ascertain how OpenJPA recognises an enum when mapping data to such a field. I can't find the code- could someone point me to it or give me a hint?I think that AnnotationPersistenceMappingParser.parseEnumerated() is probably the place to start. I found this by searching for usages of EnumValueHandler (the thing responsible for enums).
OK, great. Found it.
if ("java.lang.Enum".equals(type.getSuperclass().getName()))
Adam
