Grails/Hibernate: No row with the given identifier exists

user2679352 picture user2679352 · Oct 4, 2013 · Viewed 12.1k times · Source

I have a domain as follow:

class Author {
    String id
    static hasMany = [accounts: Account]
    static belongsTo = Account
    static mapping = {
        accounts joinTable: [name: "SOMETABLE", key: 'SOMEFIELD'], 
                 ignoreNotFound: true
    }
    static constraints = {}
}

I get the following error when no record are found. I tried the ignoreNotFound, it not working.

error message: accounts=org.hibernate.ObjectNotFoundException: 
No row with the given identifier exists: 
[com.myapplication.Account#123465489785]

it happens when trying to select join 2 records that you dont have access to insert in the db. Is there a workaround, please?

Answer

Foo Bar User picture Foo Bar User · Oct 4, 2013

it means there is no row in your Account table with id 123465489785. Your author has an account with id 123465489785. Hibernate cannot find it so it throws an exception. if its a new account make the id on the account null so that hibernate knows its a new row.