对象属性有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. 基本数据类型--------------------集合set()

    一.作用:集合.list.tuple.dict一样都可以存放多个值,但是集合主要用于:关系运算.去重 # 1.1 关系运算 friends1 = ["zero","kev ...

  2. drf路由与认证

    目录 一.路由 1 没有继承视图集的视图类 2 继承了视图集的视图类 3 继承自ModelViewSet的路由写法(自动生成) 二.认证 1 drf认证的源码分析 2 自定义认证类的使用 一.路由 三 ...

  3. Python split分割字符串

    s = input(); str = s.split("-") print("{}+{}".format(str[0],str[-1]))

  4. 卸载wsl子系统

    1>在powershell中输入下面的代码 wslconfig /l #显示出你安装的列表. wslconfig /u debian #debian为上述列表中的名字 注销子系统 2>打开 ...

  5. java 面向对象(十一):关键字:package/import

    1.1 使用说明: * 1.为了更好的实现项目中类的管理,提供包的概念 * 2.使用package声明类或接口所属的包,声明在源文件的首行 * 3.包,属于标识符,遵循标识符的命名规则.规范(xxxy ...

  6. Python之网络编程 Socket编程

    本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实 ...

  7. mysql间隙锁

    什么是间隙锁(gap lock)? 间隙锁是一个在索引记录之间的间隙上的锁. 间隙锁的作用? 保证某个间隙内的数据在锁定情况下不会发生任何变化.比如我mysql默认隔离级别下的可重复读(RR). 当使 ...

  8. .NET 开源项目 StreamJsonRpc 介绍[下篇]

    阅读本文大概需要 9 分钟. 大家好,这是 .NET 开源项目 StreamJsonRpc 介绍的最后一篇.上篇介绍了一些预备知识,包括 JSON-RPC 协议介绍,StreamJsonRpc 是一个 ...

  9. OSCP Learning Notes - WebApp Exploitation(1)

    Installing XSS&MySQL FILE Download the Pentester Lab: XSS and MySQL FILE from the following webs ...

  10. Go的100天之旅-06数组和Slice

    目录 数组 Slice 数组 Go的数组和其它语言基本上一样,是长度固定的特定类型元素组成的序列,这基本上是所有语言数组的特性.和其它语言相比差异主要在声明和初始化的写法上,下面是简单声明一个数组: ...