Java Grails/Hibernate:不存在具有给定标识符的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19187534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Grails/Hibernate: No row with the given identifier exists
提问by user2679352
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.
找不到记录时出现以下错误。我试过ignoreNotFound,它不起作用。
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?
它发生在尝试选择连接 2 条您无权插入到数据库中的记录时。请问有解决办法吗?
回答by Foo Bar User
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.
这意味着您的Account
表中没有带有 id 的行123465489785
。您的作者有一个 ID 为 123465489785 的帐户。Hibernate 找不到它,因此它抛出异常。如果它是一个新帐户,则使帐户上的 id 为空,以便休眠知道它的新行。
回答by biniam
Adding ignoreNotFound = true
mapping solves the issue according to the Grails documentation.
ignoreNotFound = true
根据Grails 文档,添加映射可以解决该问题。