2013-10-04 29 views
5

我有一個域名爲:的Grails /休眠:與給定的標識符的行存在

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記錄,你沒有訪問插入數據庫時​​發生。 請問有沒有解決辦法?

回答

2

這意味着您的Account表中沒有行,其ID爲123465489785。您的作者有一個ID爲123465489785的帳戶.Hibernate無法找到它,因此它會引發異常。如果它的一個新帳戶使該帳戶上的id爲空,以便hibernate知道它的新行。

+0

我知道這意味着Author表中沒有行存在。但是有沒有辦法讓Grails忽略它?我們可以告訴Grails只返回一個空列表嗎? – user2679352

+1

你想做什麼?保存作者? –

+0

這是一個遺留數據庫。我正在閱讀記錄。我們不會更新任何記錄。有一個多對多的關係,這就是爲什麼我必須指定joinTable。 – user2679352