Search code examples
grailsgrails-ormlegacy-database

Grails, legacy database fails to get correct type of ID


There is a lot of problems using tables from a legacy DB. One is a table with name "RoleType" which has it's ID named "RoleType"

Here is the important fragment of the domain class:

class RoleType {
    int roleType
....
    static mapping = {
        table 'RoleType'
        version false
        id column: 'roleType', type:'int', generator:'assigned'
        roleType column: 'RoleType'

Error-listing:

    Caused by: org.hibernate.PropertySetterAccessException:
 IllegalArgumentException occurred while calling setter for property
 [com.torntrading.legacy.RoleType.id (expected type = java.lang.Long)];
     target = [com.torntrading.legacy.RoleType : (unsaved)], property value = [1] 
setter of com.torntrading.legacy.RoleType.id

What can I do to solve this?


Solution

  • You're specifying the column for the id, but not which property in the domain is representing it.

    id name: 'roletype', type:'int', generator:'assigned' roleType column: 'RoleType'

    Should do it