Groovy Grails Hibernate:批量更新从更新 [0] 返回了意外的行数;实际行数:0;预期:1

Groovy Grails Hibernate : batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

我是 Hibernate 和 Groovy 的新手,我不知道为什么我在这段代码中得到了错误 ID。 我的 Grails 版本是 2.1.1

Grails-app/Domain 使用 Hibernate

class Deposit implements Validateable{

BigInteger **id**
BigDecimal amount
BigDecimal currentBalance

static mapping = {
    datasource 'test'
    table 'DEPOSIT'
    id column: "ID"
    amount column: "amount"
    currentBalance column: "currentBalance"

    version false
}

存款控制器

def depositTrx(){
    def savedata = new Deposit()    
    savedata.id=3;
    savedata.amount=122223;
    savedata.currentBalance=1511122;
    savedata.save()
    redirect(uri: "/Deposit")
}

如果我在 grails-app/Domain 中使用 id,我会得到这个错误: 批量更新从更新 [0] 返回了意外的行数;实际行数:0;预期:1

当我更改 grails-app/Domain: id 变为 ide 或其他任何内容时,代码成功保存数据到数据库,但页面显示此错误 Deposit entry中的null id(出现异常后不刷新Session)

如果您希望能够手动分配 id 您可以将生成器设置为已分配:

static mapping = {
    id generator: 'assigned', column: "ID"
    ...
}

http://docs.grails.org/3.1.1/ref/Database%20Mapping/id.html