Eddard Stark
Eddard Stark

Reputation: 3595

Custom primary key for grails domain

I have a legacy database (MSSQL) that I am trying to connect via grails. The table has a primary key with name "ClaimSubmissionId". How do I map this key to grails domain? Currently my grails domain looks like this :

class ClaimSubmission {

    Integer ClaimSubmissionId

    ... Other Fields ...

    static constraints = {
    }

    static mapping = {
        datasource("mssql_external")
        table 'ClaimSubmissionRequests'
        version false
        id generator: 'identity', name: "ClaimSubmissionId", type: 'Integer', column:"ClaimSubmissionId"

        columns{
//            id column: "ClaimSubmissionId"
            ... Other Fields ...
        }
    }
}

The field "ClaimSubmissionId" should work as a primary key, must be unique, auto-assigned and incremental. Currently I am getting this error

Error evaluating ORM mappings block for domain [com.company.project.ClaimSubmission]:  null

I also tried putting id field in columns closure as shown above in commented section but did not work.

Upvotes: 1

Views: 1779

Answers (1)

dmahapatro
dmahapatro

Reputation: 50245

This should do:

class ClaimSubmission {
    Integer claimSubmissionId

    static mapping = {
        datasource("mssql_external")
        table 'ClaimSubmissionRequests'
        version false

        id column: "ClaimSubmissionId", //actual column name from db
           name: "claimSubmissionId",   //used lower camelCase for field names
           type: 'integer',             //lower case 
           generator: 'identity'

    }
}

Upvotes: 2

Related Questions