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

遇到这个异常实属不小心所致,最初看到异出的错误信息时我误认为是主键为空所致。一着急竟然把entry当成了entity理解,真是让人笑话^_^。

其实个该异常信息是在提示我们没有为数据中的非空字段设置值。呵呵!看,够笨的吧。怎么会忘记为非空字段设置值呢?当然一般我们是不会犯这样的错。但是需要说的一点是,在数据的设计中比如SqlServer,我们为某个非空字段设置了默认值。如果我们在通过Hibernate增加一条记录的时候我们必须显式的通过setXxx方法为该字段(/属性)赋值(/默认值)。因为在保存之前Hibernate会检查该非空字段对应的实体属性是否为空。我就是忽略了这一点,所以才会造成上面的异常。

如果不想对有默认值的非空字段进行显式赋值的话,我们可以通过xxx.hbm.xml配置文件来实现,也就是在配置文件中给出该字段的默认值

null id in entry (don't flush the Session after an exception occurs)的更多相关文章

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

    最近在学习基于ssh的注解的系统,然后在实现往数据库增加记录时可以增加第一个,第二个就报错,在网上查了很多资料,大多都是 该异常信息是在提示我们没有为数据中的非空字段设置值. 然后就一直没有明白 明明 ...

  2. 报错:org.hibernate.AssertionFailure: null id in com.tt.hibernate.entities.News entry (don't flush the Session after an exception occurs)

    在使用hibernate创建数据库的表格时,出现了如下报错: 十二月 28, 2016 10:17:02 上午 org.hibernate.tool.hbm2ddl.SchemaExport perf ...

  3. org.hibernate.AssertionFailure: null id in xxx entry (don't flush the Session after an exception occurs)

    网上找了很久,发现造成原因有很多种,后来终于发现了端倪:看提示是发生了异常,查看业务代码,发现有这个逻辑:先插入记录,如果有唯一键约束异常(并发造成),catch时查询已存在的记录,查询的时候就报了此 ...

  4. 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 Sessio ...

  5. null id in com.rocky.** entry 错误处理

    1. 概述 使用hibernate往mysql数据库插入记录出错如下 10:37:57,364 ERROR [AssertionFailure] an assertion failure occure ...

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

    今日在开发时遇到一个比较奇怪的问题,保存时报这个异常: org.hibernate.AssertionFailure: null id in com.aa.TShoucang null id,这个是什 ...

  7. AndroidStudio编译错误:Error: null value in entry: blameLogFolder=null

    今天写项目的时候,电脑开了个WiFi热点,然后这个热点和window驱动不兼容,有时候会导致电脑重启,重启之后AndroidStudio编译就报错了, Error: null value in ent ...

  8. 报错 ——Error evaluating expression 'id != null id > 0'.

    Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error qu ...

  9. Hibernate二次学习二----------session.flush、session.doWork

    目录 1. session 2. session.flush 3. session.doWork 4. 完整代码 5. 总结 © 版权声明:本文为博主原创文章,转载请注明出处 1. session H ...

随机推荐

  1. post请求(headers里有属性)报错:Request header field xxx is not allowed by Access-Control-Allow-Headers in preflight response

    post 请求,headers里有属性(xxx).请求时报错: XMLHttpRequest cannot load <url>. Request header field xxx is ...

  2. HTTP报头:通用报头,请求报头,响应报头和实体报头

    缓存控制优先级从高到低分别是Pragma -> Cache-Control -> Expires 报头 每一个报头都是由 [名称 + ":" + 空格 + 值 + ] ...

  3. hello word 应用程序的编写

    1.各类文件的书写 src中的文件: hello文件夹中的Makefile文件 # # Copyright (C) - OpenWrt.org # # This is free software, l ...

  4. 【python】实例-答题系统

    #!/usr/bin/env python from operator import add, sub from random import randint, choice ops = {'+': a ...

  5. 【android】android 常用adb 和 adb shell 命令

    db是SDK自带的工具,可实现桥接功能:adb shell 可以与手机系统建立交互,是基于andoid Linux系统下的操作 ADB常用命令: 1. 查看设备         adb  device ...

  6. android 获取当前 activity

    ActivityManager am = (ActivityManager) this .getSystemService(ACTIVITY_SERVICE); List<RunningTask ...

  7. MySQL 报错记录

    #--------------------------------------------------------------------------------------------------- ...

  8. 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  9. CentOS 6.6下安装配置Tomcat环境

    本文转载至:http://www.linuxidc.com/Linux/2015-08/122234.htm 实验系统:CentOS 6.6_x86_64 实验前提:防火墙和selinux都关闭 实验 ...

  10. keras中调用tensorboard:from keras.callbacks import TensorBoard

    from keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn ...