对象属性有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. C# DataTable与Excel读取与导出

    /// <summary> /// Excel->DataTable /// </summary> /// <param name="filePath&q ...

  2. day54 作业

    编写代码,将当前日期按"2017-12-27 11:11 星期三"格式输出(提示:switch结构) var date = new Date() ymd = data.toLoca ...

  3. vue重置data里的值

    this.$options.data() 这个可以获取原始的data值,this.$data 获取当前状态下的data,拷贝重新赋值一下就行了. Object.assign(this.$data, t ...

  4. java 数据结构(七):Collection接口

    1.单列集合框架结构|----Collection接口:单列集合,用来存储一个一个的对象* |----List接口:存储序的.可重复的数据. -->“动态”数组* |----ArrayList. ...

  5. 对掌机游戏Pokemon的一部分系统的拆解流程图

    整体系统拆解 POKEMON系统拆解 属性.技能.进化形态 属性提升系统 种族值说明: 所有Pokemon都拥有自己的种族的种族值,且固定(例如:小火龙:309, 皮卡丘: 320) 种族值是各项属性 ...

  6. 网络编程-UDP、TCP

    总结

  7. c# Winfrom-DataGridView实现筛选功能

      //应对用户需求,需要在DataGridView中直接进行筛选功能,在网上找了一些代码加上自己修改整理过后的类,仅供参考! //上面代码可以直接创建类库项目生成DLL文件,下面代码为另外项目引用创 ...

  8. 【Python学习笔记七】从配置文件中读取参数

    将一些需要更改或者固定的内容存放在配置文件中,通过读取配置文件来获取参数,这样修改以及使用起来比较方便 1.首先是配置文件的写法如下一个environment.ini文件: 里面“[]”存放的是sec ...

  9. Java中Map的entrySet()详解

    转发:原博客 由于Map中存放的元素均为键值对,故每一个键值对必然存在一个映射关系.Map中采用Entry内部类来表示一个映射项,映射项包含Key和ValueMap.Entry里面包含getKey() ...

  10. Makefile中的一个坑

    问题描述:Makefile中,我想将一个变量的后缀全部进行替换,如将所有的.c后缀变成.d后缀 方法:$(CUR_SOURCE: .c = .d ) 说明:查阅相关资料,了解到上述这种语法就可以将所有 ...