欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

hibernate常见错误及解决方法总结

发布时间:2025/3/20 编程问答 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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”;
}

6、object references an unsaved transient instance - save the transient instanc

解决:需要设置级联的对象cascade = “sava-update”,这样才会保存级联的对象。主要的问题在于没有给其对象设置id值,这样的话保存的时候不是一个持久化的对象。

7.Field 'uuid' doesn't have a default value

解决:这是由于在设计表的时候忘记给其主键设置自增了。

8. org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity:

解决:这是因为没有配置实体类的映射文件造成的。

总结

以上是生活随笔为你收集整理的hibernate常见错误及解决方法总结的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。