Grails/Hibernate:不存在具有给定标识符的行

use*_*352 6 java grails hibernate grails-orm grails-domain-class

我有一个域名如下:

class Author {
    String id
    static hasMany = [accounts: Account]
    static belongsTo = Account
    static mapping = {
        accounts joinTable: [name: "SOMETABLE", key: 'SOMEFIELD'], 
                 ignoreNotFound: true
    }
    static constraints = {}
}
Run Code Online (Sandbox Code Playgroud)

没有找到记录时,我收到以下错误.我尝试了ignoreNotFound,它无法正常工作.

error message: accounts=org.hibernate.ObjectNotFoundException: 
No row with the given identifier exists: 
[com.myapplication.Account#123465489785]
Run Code Online (Sandbox Code Playgroud)

尝试选择您无权在数据库中插入的连接2记录时会发生这种情况.请问有解决方法吗?

Foo*_*ser 3

这意味着您的表中没有Accountid 的行123465489785。您的作者有一个 ID 为 123465489785 的帐户。Hibernate 无法找到它,因此会引发异常。如果它是一个新帐户,则将帐户上的 id 设置为空,以便 hibernate 知道它是一个新行。