我们首先看一下异常信息:
- net.sf.hibernate.AssertionFailure: null id in entry (don't flush the Session after
- an exception occurs)
- at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2605)
- at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2429)
- ... ...
遇到这个异常实属不小心所致,最初看到异出的错误信息时我误认为是主键为空所致。一着急竟然把entry当成了entity理解,真是让人笑话^_^。
其实个该异常信息是在提示我们没有为数据中的非空字段设置值。呵呵!看,够笨的吧。怎么会忘记为非空字段设置值呢?当然一般我们是不会犯这样的错。但是需要说的一点是,在数据的设计中比如SqlServer,我们为某个非空字段设置了默认值。如果我们在通过Hibernate增加一条记录的时候我们必须显式的通过setXxx方法为该字段(/属性)赋值(/默认值)。因为在保存之前Hibernate会检查该非空字段对应的实体属性是否为空。我就是忽略了这一点,所以才会造成上面的异常。
如果不想对有默认值的非空字段进行显式赋值的话,我们可以通过xxx.hbm.xml配置文件来实现,也就是在配置文件中给出该字段的默认值。
分享到:
相关推荐
hibernate 常见异常非常不错的,hibernate 常见异常非常不错的
hibernate异常文档.xls hibernate异常文档.xls
Hibernate Search in Action aims not only at providing practical knowledge of Hibernate Search but also uncovering some of the background behind Hibernate Search’s design. We will start by describing ...
hibernate Search in action
整理了hibernate常见的异常,有了此文档,开发中遇到的Hibernate异常调试更轻松
Hibernate In Action 3 第三部分 中文 入门教程
hibernate_in_action 源码
hibernate常见异常,hibernatejpa注解使用开发的解决方案
Hibernate简单实例 Hibernate in Myeclipse,也就是java Web整合开发自学手册第23章的实例!调试了很久终于可运行!现在共享!希望对学习java web的朋友有帮助!直接在myeclipse添加项目,可运行!
Hibernate In Action 电子书 pdf
Hibernate In Action(Java.Persistence.with.Hibernate)的源码,从该书的出版社网站上下载下来的.
hibernate in action 是绝对的中文版,完整版!!!
Hibernate In Action中文版电子书
As a major revision of the popular Hibernate in Action, it builds on the same single example application to introduce and explain the latest Hibernate 3.2 in detail. In addition, the new and ...
Emmanuel Bernard joined the Hibernate team in 2003 and is now the lead developer of Hibernate Annotations and Hibernate EntityManager, two key projects on top of the Hibernate core implementing the ...
Hibernate Search in action (pdf && code)
Hibernate in action Spring in Action Struts In Action 全是英文版
hibernate in action 第二版中文版 j2ee课程教学参考书籍
hibernate in actionhibernate in actionhibernate in action