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.mark(int)与 in.reset() 但是FileInputStream流对象此方法无效 因此可改用 BufferedInputStream 如:
LobHelper lobHelper = session.getLobHelper();
InputStream in = new BufferedInputStream(new FileInputStream(this.getClass().getResource("/j.jpg").getFile()));
//或用this.getClass(),getResourceAsStream();
in.mark(in.available());
Blob bookPic = lobHelper.createBlob(in, in.available()); book.setBookPic(bookPic);
//调用流的reset()
in.reset();
book2.setBookPic(bookPic);
具体reset() 与mark(int)使用介绍可查看其它介绍 因此在处理这类特殊对象的时候应由其要注意这种细节 当然要是关闭流也应在save()之后,否则同样会报这样的错误
org.hibernate.AssertionFailure: null id 错误的更多相关文章
- 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 ...
- 报错: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 ...
- org.hibernate.AssertionFailure: null id in xxx.xx.xx的问题
今日在开发时遇到一个比较奇怪的问题,保存时报这个异常: org.hibernate.AssertionFailure: null id in com.aa.TShoucang null id,这个是什 ...
- org.hibernate.AssertionFailure: null id in xxx entry (don't flush the Session after an exception occurs)
网上找了很久,发现造成原因有很多种,后来终于发现了端倪:看提示是发生了异常,查看业务代码,发现有这个逻辑:先插入记录,如果有唯一键约束异常(并发造成),catch时查询已存在的记录,查询的时候就报了此 ...
- org.hibernate.AssertionFailure: null id don't flus
我的是字段编码和数据库不匹配,是爬的微博数据
- null id in com.rocky.** entry 错误处理
1. 概述 使用hibernate往mysql数据库插入记录出错如下 10:37:57,364 ERROR [AssertionFailure] an assertion failure occure ...
- 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) 遇到这个异常实属不小心所致,最初看到异出的错误信息时我误认为是 ...
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.trs.om.bean.User.retryCount
六月 29, 2019 5:42:45 下午 org.apache.catalina.core.AprLifecycleListener init信息: The APR based Apache To ...
- org.hibernate.AssertionFailure:collection[......] was not processed by flush()
八月 12, 2016 11:00:49 上午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() f ...
随机推荐
- linux安装phantomjs
一.下载PhantomJS: 从官网http://phantomjs.org/download.html下载linux64位的安装包即 phantomjs-2.1.1-linux-x86_64.ta ...
- Kafka入门(1):概述
摘要 在本文中,我将从为什么需要消息队列开始讲起,举两个小例子,跟你聊聊目前消息队列的一些使用场景. 比如消息队列在复杂系统中的解耦,又比如消息队列在高并发下的场景如果让流量变得更平缓. 随后我会跟你 ...
- MATLAB GUI之ABC
GUIDE 属性设置 name 更改名字 logo 在GUI的".m"文件中的OpeningFcn函数或者OutputFcn函数中添加以下代码: % 设置页面左上角的 LogoI ...
- 李航统计学习方法(第二版)(十):决策树CART算法
1 简介 1.1 介绍 1.2 生成步骤 CART树算法由以下两步组成:(1)决策树生成:基于训练数据集生成决策树,生成的决策树要尽量大;(2)决策树剪枝:用验证数据集对己生成的树进行剪枝并选择最优子 ...
- python 装饰器(二):装饰器基础(二)变量作用域规则,闭包,nonlocal声明
变量作用域规则 在示例 7-4 中,我们定义并测试了一个函数,它读取两个变量的值:一个是局部变量 a,是函数的参数:另一个是变量 b,这个函数没有定义它. >>> def f1(a) ...
- 利用EasyExcel进行对表格数据的写入
一导入依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</ ...
- oracle添加配置多个端口监听
原来配置:listener.ora文件如下: LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOS ...
- Linux 后台启动 Redis
1. 修改 redis.conf 首先,这里有一个坑 ! 不同的 redis版本,在安装的时候,redis.conf 的路径稍微有些不同 redis.conf 可能出现的三个位置: /etc/redi ...
- 用Tableau制作官网流量周报
好久没写博客了,上班摸鱼时间分享一下在工作中做的东西吧,先上图. 数据方面取自百度统计,身处传统类型公司,官网没有数据库,只好将就一下啦,反正是免费的,体验也还可以. 关于百度统计注册.添加管理站点和 ...
- javascript兼容问题 : let降级到var 遇到的闭包问题的解决方法
我用 for(let x in y) 循环一个图片元素数组. for (let x in arr) { arr[x].onload = function(){ /* ... */ } } 这样写是没 ...