首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

用hibernate往数据库save记录抛出错误,不知是什么原因,各位帮看看,找了很久了

2012-01-02 
用hibernate往数据库save记录抛出异常,不知是什么原因,各位帮看看,找了很久了the detached instance passe

用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要求每个表必须有主键,否则的话在生成映射文件的时候将整个表的所有字段当成复合主键
如果是删除则必须给主键字段(属性)赋值,如果是复合主键则必须将全部复合主键字段赋值才能删除

热点排行