Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails/Hibernate: No row with the given identifier exists

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?

like image 949
user2679352 Avatar asked Oct 04 '13 17:10

user2679352


2 Answers

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.

like image 69
Foo Bar User Avatar answered Oct 21 '22 13:10

Foo Bar User


Adding ignoreNotFound = true mapping solves the issue according to the Grails documentation.

like image 34
biniam Avatar answered Oct 21 '22 12:10

biniam