对象属性有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. testNG jar包启动找不到org.testng.TestNG

    主要是因为打包时依赖的jar包没有打入,网上有很多需要将对应的jar单独拷贝出来然后通过classpath引用启动,但是感觉这个就是个无底洞.拷贝了这么多个包最后还是说找不到ObjectId 启动命令 ...

  2. 基于web的图书管理系统设计与实现

    原文链接:基于web的图书管理系统设计与实现 系统演示链接:点击这里查看演示 01 系统简述     图书管理系统就是利用计算机,结合互联网对图书进行结构化.自动化管理的一种软件,来提高对图书的管理效 ...

  3. MySQL数据库06 /数据库总结

    MySQL数据库06 /数据库总结 目录 MySQL数据库06 /数据库总结 1. 数据库/DBMS 2. 数据库分类 3. 修改密码 4. 库操作 5. 表操作 6. 存储引擎 7. 事务 8. 约 ...

  4. 机器学习实战基础(二十五):sklearn中的降维算法PCA和SVD(六) 重要接口,参数和属性总结

    到现在,我们已经完成了对PCA的讲解.我们讲解了重要参数参数n_components,svd_solver,random_state,讲解了三个重要属性:components_, explained_ ...

  5. 数据可视化之PowerQuery篇(十八)Power BI数据分析应用:结构百分比分析法

    ​https://zhuanlan.zhihu.com/p/113113765 本文为星球嘉宾"海艳"的PowerBI数据分析工作实践系列分享之二,她深入浅出的介绍了PowerBI ...

  6. Java匿名对象介绍

    Java匿名对象介绍 什么是匿名对象? 顾名思义就是没有变量名的对象,即创建对象时,只有创建对象的语句,却没有把对象地址值赋值给某个变量. 匿名对象命名格式:以Scanner类举例 new Scann ...

  7. 资深CIO介绍如何选型OA系统的?

    OA办公系统成为企业管理的标配软件,在于可有效加强组织管理能力,提高员工协同效率,助力企业科学决策,合理分配企业资源,提升企业综合实力与市场竞争力.企业OA选型的经验总结来说也就是品牌.技术.产品.服 ...

  8. django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.解决办法

    "E:\API_Manager_PlatForm\venv\lib\site-packages\django\db\backends\mysql\base.py"在这个路径里件把b ...

  9. maven&nexus_repository 私库搭建与使用

    一.nexus仓库安装 1,http://www.sonatype.org/nexus/    下载sso版本,免费2,tar -zxvf nexus-2.11.1-01-bundle.tar.gz3 ...

  10. Windows File Recovery - 微软官方文件恢复工具

    假如你不小心误删除了文件或因各种意外情况丢失数据后,你可以通过 微软这款工具 这个工具来尝试恢复它们.WinFR 工具支持读取本机硬盘.移动硬盘.U 盘,或者连接相机.手机.使用读卡器来恢复 SD.T ...