Hibernate報錯:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解決辦法

報錯信息:數據庫

org.hibernate.event.internal.DefaultLoadEventListener onLoad
INFO: HHH000327: Error performing load command : org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.weixin.db.model.Adminusers#15]

報錯分析:ide

Hibernate的映射文件,表A裏關聯了表B的主鍵,當查詢表A時,在B表裏找不到對應記錄時就會報錯,若是隻是邏輯刪除不會報這種錯誤,只有當表B裏測試沒有id爲15的這條數據了纔會報錯(已實際測試過);上面報錯信息實體類後面【#15】表示實體類對應表id=15的記錄找不到。也就是存在垃圾數據,多是由於沒有連帶刪除。測試

 

解決辦法:fetch

1. 修改配置文件加上 not-found="ignore" 」spa

即:hibernate

<many-to-one name="adminusers" class="com.weixin.db.model.Adminusers"
     fetch="select" lazy="false" not-found="ignore">

2. 要麼就把垃圾數據從數據庫刪掉。code

 

項目中遇到的問題,記錄一下。orm

相關文章
相關標籤/搜索