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

来源:互联网 发布:淘宝买的ipad靠谱吗 编辑:程序博客网 时间:2024/06/06 02:55
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:

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

0 0