We have some legacy database mappings in GORM and several have a primary key which is an enumeration. The enumeration are stored using the string values, not the ordinals.
For example:
class AccountingGLMap {
AccountingTypeCode id
String typeCode
static mapping = {
id(column: 'accountingTypeCode', generator: 'assigned')
}
}
When you try to retrieve an instance, you get:
| Error 2012-02-23 10:32:41,319 [pool-5-thread-1] ERROR context.GrailsContextLoader - Error executing bootstraps: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize
I have verified that the values in the table map properly into the enumeration given (I can instantiate the object with the Enum so long as it’s not the primary key). If we change the Enum to a String, everything works fine.
I did see an article claiming you can’t use an Enum as the primary key when using JPA, but even that was disputed.
Anyone have experience doing this?
EDIT: For reference we are using 2.0.1 against an Oracle database.
Add
type: 'string'to your id mapping and then add a setter for id that takes a String input like so: