1
votes

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.

1

1 Answers

2
votes

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'

    }
}