hibernate常见错误及解决方法总结
生活随笔
收集整理的這篇文章主要介紹了
hibernate常见错误及解决方法总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、org.hibernate.PropertyNotFoundException: field [cid] not found on org.sihai.shop.categorySecond.CategorySecond
解決:一般是在hbm.xml文件中的屬性和實體中的屬性不對應。
2、org.hibernate.MappingException: An association from the table product refers to an unmapped class: CategorySecond***解決:*** class需要寫全路徑
3、mysql刪除有外鏈索引數據 Cannot delete or update a parent row: a foreign key constraint fails erty references a null or transient value: org.sihai.shop.product.Product.categorySecond; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: org.sihai.shop.product.Product.categorySecond解決:在做刪除的時候,因為直接獲取到的對象是瞬時態的對象,不是持久態,不能刪除,所以需要在刪除的時候,先根據id查詢到這個持久態的對象,然后再刪除。
// 后臺:刪除商品
public String delete() {
product = productService.findByPid(pid);
productService.delete(product);
return “deleteSuccess”;
}
解決:需要設置級聯的對象cascade = “sava-update”,這樣才會保存級聯的對象。主要的問題在于沒有給其對象設置id值,這樣的話保存的時候不是一個持久化的對象。
7.Field 'uuid' doesn't have a default value解決:這是由于在設計表的時候忘記給其主鍵設置自增了。
8. org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity:解決:這是因為沒有配置實體類的映射文件造成的。
總結
以上是生活随笔為你收集整理的hibernate常见错误及解决方法总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle数据库之PL/SQL
- 下一篇: struts2常见错误及解决总结