質問

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
役に立ちましたか?

解決

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.

他のヒント

You can generate-views and put explicit all model's propetries in indesx.gsp (Example):

<f:table collection="${domainTestList}" properties="['pro1', 'pro2', 'pro3', 'pro4']" />

I hope that makes sense!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top