解決Hibernate映射導致的幾個常見異常

HibernatePHPHTML
異常1:not-null property references a null or transient value
解決方法:將“一對多”關係中的“一”方,not-null設置爲false
(參考資料:http://www.thearcmind.com/confluence/pages/viewpage.action?pageId=212)


異常2:org.hibernate.TransientObjectException: object references an unsaved transient instance
解決方法:cascade="save-update,persist"
(參考資料:http://www.laliluna.de/254.html)


異常3:org.hibernate.QueryException: could not resolve property
解決方法:"from Category category where category.userID = :userID"修改爲"from Category category where userID = :userID"或者"from Category category where category.user.id = :userID"
(參考資料:http://www.laliluna.de/277.html)


異常4:could not initialize proxy - the owning Session was closed
解決方法:設置lazy爲false
(參考資料:http://forum.springframework.org/showthread.php?t=27993)
發佈了28 篇原創文章 · 獲贊 7 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章