user2679352
user2679352

Reputation: 81

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?

Upvotes: 7

Views: 12821

Answers (3)

Rizky Yoga Oktora
Rizky Yoga Oktora

Reputation: 39

You can use Author.findById(id) instead of Author.get(id)

Upvotes: 0

biniam
biniam

Reputation: 8199

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

Upvotes: 2

Foo Bar User
Foo Bar User

Reputation: 2491

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.

Upvotes: 3

Related Questions