日期:2014-05-18  浏览次数:20670 次

用hibernate往数据库save记录抛出异常,不知是什么原因,各位帮看看,找了很久了
the detached instance passed to delete() had a null identifier; nested exception is org.hibernate.TransientObjectException: the detached instance passed to delete() had a null identifier
org.hibernate.TransientObjectException: the detached instance passed to delete() had a null identifier


------解决方案--------------------
没有找到合适的主键
------解决方案--------------------
你这到底是增加还是删除
如果是增加,就要查找你是怎么定义你所操作的那个表/类的主键,如果是assigned类型的,就要人为给主键的字段赋值;如果是序列,则必须数据库中存在此序列;还有一种情况就是你的数据库中的表根本就没有主键,而Hibernate要求每个表必须有主键,否则的话在生成映射文件的时候将整个表的所有字段当成复合主键
如果是删除则必须给主键字段(属性)赋值,如果是复合主键则必须将全部复合主键字段赋值才能删除