7

我有一个域如下:

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

找不到记录时出现以下错误。我尝试了ignoreNotFound,它不起作用。

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

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

4

2 回答 2

3

这意味着您的Account表中没有 id行123465489785。您的作者有一个 ID 为 123465489785 的帐户。Hibernate 找不到它,因此它会引发异常。如果它是一个新帐户,则使帐户上的 id 为空,以便休眠知道它是一个新行。

于 2013-10-04T17:50:50.737 回答
2

ignoreNotFound = true根据Grails 文档,添加映射解决了该问题。

于 2015-12-24T20:49:30.397 回答