grails域的自定义主键

时间:2014-04-04 06:04:46

标签: grails gorm primary-key

我有一个遗留数据库(MSSQL),我试图通过grails连接。该表有一个名为" ClaimSubmissionId"的主键。如何将此密钥映射到grails域? 目前我的grails域看起来像这样:

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 ...
        }
    }
}

字段" ClaimSubmissionId"应作为主键,必须是唯一的,自动分配的和增量的。目前我收到此错误

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

我也尝试将id字段放在列闭包中,如上面注释部分所示,但是没有用。

1 个答案:

答案 0 :(得分:2)

这应该做:

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'

    }
}