【问题标题】:Groovy Grails Hibernate : batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1Groovy Grails Hibernate:批量更新从更新 [0] 返回了意外的行数;实际行数:0;预期:1
【发布时间】:2020-09-27 04:29:23
【问题描述】:

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

使用 Hibernate 的 Grails-app/Domain

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 或其他任何内容时,代码成功将数据保存到数据库,但页面显示此错误 存款项中的空id(发生异常后不要刷新会话)

【问题讨论】:

  • 您使用的是什么版本的 grails?您是否正在更新现有数据?我认为也许将 ID 分配给一个新对象可能是问题 - 你可以试试 def saveData = Deposit.load(3) 吗?
  • @erichelgeson 我使用 Grails-2.1.1。我想保存(添加)新交易。

标签: mysql hibernate grails groovy


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多