org.hibernate.AssertionFailure: null id in xxx.xx.xx的问题


今日在开发时遇到一个比较奇怪的问题,保存时报这个异常:

Java代码  

  1. org.hibernate.AssertionFailure: null id in com.aa.TShoucang

null id,这个是什么回事呢?数据库是自动增长了,hibernate映射文件也一切正常的了,看了后台也打印出了insert into ....这个的语句了,但为什么就是插入不成功呢?

本着知之为知之,不知google之的精神,google了一下,都是说数据库与映射文件不对应,数据库设置了不为null,但hibernate里的映身文件设置了为null等等的.

发现都不是这个的问题,后来直接将打印出来的sql语句发送到数据库里执行一下,也是报一样的错,也就是说与hibernte没关系了.如以下这一句:

Java代码  

  1. insert into t_shoucang (url, describe, objic, userid, createuserid, createusername, createtime, updatetime, id) values (‘aa‘, ‘bb‘, ‘cc‘, ‘dd‘, ‘ee‘, ‘ff‘, ‘2010-01-01‘, ‘2010-01-01‘, ‘abcd123‘);

发现describe这个字段变成了蓝色,是关键字,加多一个s后,再运行,OK了.

所以总结得出,null id这个问题时,有可能是字段里用到了数据库的关键字了.

今日又再出现这个问题了,并不是数据库关键字的原因了,如果数据库里设置了某个字段值不为null,而你保存的时候就设置了为null,也会报这个异常的。郁闷....

时间: 2024-08-03 14:19:15

org.hibernate.AssertionFailure: null id in xxx.xx.xx的问题的相关文章

java错误:org.hibernate.AssertionFailure: null id in xxx.xx.xx的问题

经常遇到这种问题,在添加数据的时候: 看到这种情况,你是不是容易想到配置问题?缓存问题?主键问题? 不过一般只要不是新项目,而且主键已经配置了自动增长,那么就是其它问题了. 以下就是我遇到过的比较坑人的现象,但往往不会想到这方面,浪费不少时间: 1.做添加功能时,因为新加了个字段,结果数据库的字段忘了添加,然后就报这错: 2.数据库字段和代码中配置类型没有匹配(比如价格在数据库中是个double,代码中写了个String):

org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Session after a

1.错误描述 org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Session after an exception occurs) at org.hibernate.event.internal.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:77) at org.hib

org.hibernate.AssertionFailure: null id don‘t flu

严重: Servlet.service() for servlet default threw exceptionorg.hibernate.AssertionFailure: null id in com.iprecare.entity.Inventroyrecord entry (don't flush the Session after an exception occurs)    at org.hibernate.event.def.DefaultFlushEntityEventLis

org.hibernate.AssertionFailure: null id 错误

对象属性有Blob类型: 而Blob需在输入流中读取: InputStream in = new FileInputStream(url.getFile()); Blob bookPic = lobHelper.createBlob(in, in.available()); book.setBookPic(bookPic); book2.setBookPic(bookPic); 如对象bookPic第二次使用的时候以无法再从in 中读取信息,因此报错 改进方法: 重新获取一次in 或使用 in.

null id in entry (don't flush the Session after an exception occurs)

null id in entry (don't flush the Session after an exception occurs) 遇到这个异常实属不小心所致,最初看到异出的错误信息时我误认为是主键为空所致.一着急竟然把entry当成了entity理解,真是让人笑话^_^. 其实个该异常信息是在提示我们没有为数据中的非空字段设置值.呵呵!看,够笨的吧.怎么会忘记为非空字段设置值呢?当然一般我们是不会犯这样的错.但是需要说的一点是,在数据的设计中比如SqlServer,我们为某个非空字段设置

null id in entry (don't flush the Session after an exception occurs) 解决方法

最近在学习基于ssh的注解的系统,然后在实现往数据库增加记录时可以增加第一个,第二个就报错,在网上查了很多资料,大多都是 该异常信息是在提示我们没有为数据中的非空字段设置值. 然后就一直没有明白 明明都赋值了 为什么还会这样 ,然后我把unique字段和非空字段去掉即//@Column(name = "zh", unique = true, nullable = false)就好了. null id in entry (don't flush the Session after an

[hibernate]org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.wa.dataprocess.query.model.AcrossDeptApply 包装类和基本数据类型的区别, 包装类默认为null,基本类型为0. public class AcrossDeptApply implements Serializable private Str

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette

org.hibernate.PropertyAccessException: Null value was assigned to a property <property column="sex"  name="sex"  type="java.lang.Boolean"/> JavaBean修改:private Boolean sex; 原因:数据库字段值为NULL,int 类型不能赋值为NULL,只能为0,但有些实际应用中,如学

为应用程序池 &#39;&#39;DefaultAppPool&#39;&#39; 提供服务的进程意外终止。进程 ID 是 &#39;&#39;xxx&#39;&#39;问题的解决方法

网上提供了很多办法,都未解决. 解决过程一波三折,依次用了下列方法: 1.解决办法 点击“开始”-“控制面板”-“管理工具”-“组件服务”-“计算机”-“我的电脑”-“DCOM”选项, 选择其下的“IIS ADMIN SERVICE”,右健选择“属性”,找到“安全”,在“启动和激活权限”中编辑“自定义”,添加帐号“Network Service”, 给该帐号赋予“本地启动”和“本地激活”的权限,重新启动IIS,(点“开始”-“运行”-“CMD”,点确定,然后运行IISRESET) 注:没有能够解