对象属性有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 错误的更多相关文章

  1. 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 ...

  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.xx.xx的问题

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

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

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

  5. org.hibernate.AssertionFailure: null id don't flus

    我的是字段编码和数据库不匹配,是爬的微博数据

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

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

  7. 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) 遇到这个异常实属不小心所致,最初看到异出的错误信息时我误认为是 ...

  8. 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 ...

  9. org.hibernate.AssertionFailure:collection[......] was not processed by flush()

    八月 12, 2016 11:00:49 上午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() f ...

随机推荐

  1. v-model修饰符

    1).lazy:取代 input 监听 change 事件. 用法: v-model.lazy="message" 效果: 在input输入框改变数据时,v-model绑定的DOM ...

  2. BFC原理解析

    BFC的概念 块格式化上下文(Block Formatting Context,BFC) 是Web页面的可视化CSS渲染的一部分,是块盒子的布局过程发生的区域,也是浮动元素与其他元素交互的区域. 它是 ...

  3. 一小时完成后台开发:DjangoRestFramework开发实践

    DjangoRestFramework开发实践 在这之前我写过一篇关于Django与Drf快速开发实践的博客,Django快速开发实践:Drf框架和xadmin配置指北,粗略说了一下Drf配置和基本使 ...

  4. java 面向对象(三十三):泛型二 泛型在集合中的使用

    1. 在集合中使用泛型之前的例子 @Test public void test1(){ ArrayList list = new ArrayList(); //需求:存放学生的成绩 list.add( ...

  5. 记SqlSugar ORM框架之找不到主键问题

    前端时间在.NetCore项目中使用SqlSugar ORM框架(引用sqlSugarCore依赖包)的时候遇到了一个奇葩问题:对表进行数据更新操作的时候,报错 “ You cannot have n ...

  6. 盘点JMeter不为人知那一些细节

    Jmeter工作原理 向服务器提交请求,并从服务器取回请求返回的结果.即建立一个线程池,多线程运行取样器产生大量负载,在运行过程中通过断言来验证结果的正确性,通过监听器来记录测试结果. 文章内容以Jm ...

  7. Ethical Hacking - NETWORK PENETRATION TESTING(13)

    Nmap Nmap is a network discovery tool that can be used to gather detailed information about any clie ...

  8. 题解 SP2713 【GSS4 - Can you answer these queries IV】

    用计算器算一算,就可以发现\(10^{18}\)的数,被开方\(6\)次后就变为了\(1\). 所以我们可以直接暴力的进行区间修改,若这个数已经到达\(1\),则以后就不再修改(因为\(1\)开方后还 ...

  9. 基于Python爬虫采集天气网实时信息

      相信小伙伴们都知道今冬以来范围最广.持续时间最长.影响最重的一场低温雨雪冰冻天气过程正在进行中.预计,今天安徽.江苏.浙江.湖北.湖南等地有暴雪,局地大暴雪,新增积雪深度4-8厘米,局地可达10- ...

  10. 新阿里云服务器从0开始配置为python开发环境

    由于每次打开linux虚拟机比较麻烦,于是尝试一下云服务器,在阿里云领取了一个月的试用服务器,这里记录一下新服务器从0配置成python开发环境的步骤,以便以后配置新服务器时有个参考. 免费领取一个月 ...