grailsnullpointerexceptiongrails-ormcomposite-keygrails-domain-class

Grails composite id throwing NullPointerException


I have a Grails 2.2.3 domain class that is throwing a NullPointerExeption regarding my composite id when I use dynamic scaffolding. I would just use the pidm field as the primary key, but occasionally there are two records with the same pidm (same employee, but maybe there is a name change or something) and Grails has trouble with the /show/ URI because multiple rows are returned. That is where the changeIndicator comes in - if changeIndicator is null, they are a current Employee. I'm wondering if the problem is that the pidm and changeIndicator are of two different types.

Does anyone know what the error might be?

Below is the class and error:

class Employee implements Serializable {

Integer pidm
String sid
String firstName
String lastName
String middleInitial
Character changeIndicator

static mapping = {
    table 'employee'

    id composite: ['pidm', 'changeIndicator']
    columns {
        pidm column: 'PIDM'
        changeIndicator column: 'CHANGE_IND'
        // more mappings
    }
    version false
}

Error:

URI
/phoneauth/employee/list
Class
java.lang.NullPointerException
Message
Cannot get property 'id' on null object

Solution

  • Your primary issue is that Hibernate does not allow a nullable column as part of a composite primary key.

    Secondarily, the Grails scaffold plugin does not handle composite keys very well.