Search code examples
mysqlhibernategrailsgroovy

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


I'm new in Hibernate and Groovy, i dont know why i got error id in this code. My Grails version is 2.1.1

Grails-app/Domain using 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
}

DepositContoller

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

if I use id in grails-app/Domain, i got this error: batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

when I change grails-app/Domain: id become to ide or whatever, the code successfully save data to database, but page show me this error null id in Deposit entry (don't flush the Session after an exception occurs)


Solution

  • If you would like to be able to manually assign the id you can set the generator to assigned:

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

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