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:

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

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值