如何儲存blob對象在sql server?實體set blob對象保存就報錯,不set blob對象就沒問題
@Test
????public?void?writeBlob()?throws?Exception{
????????Students?s=new?Students(1,?"張學友",?"男",?new?Date(),?"香港");
????????File?file=new?File("d:"+File.separator+"boy.jpg");
????????InputStream?is=new?FileInputStream(file);
????????Blob?img=Hibernate.getLobCreator(session).createBlob(is,?is.available());
????????s.setPicture(img);
????????session.save(s);
????}一月 05, 2017 3:03:04 下午 org.hibernate.AssertionFailure <init>
ERROR: HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in hibernate_test01.Students entry (don't flush the Session after an exception occurs)
2017-04-09
這一般都是導包的問題,你檢查下你導入的包文件一不一致
2017-01-09
查看一下你的數據庫中圖片字段對應的數據類型是否設為blob,我是這個原因。
2017-01-06
留意一下bean包中的持久化類的對應數據類型是否修改為Blob ?還有對應的hbm.xml里面 列的property的type也是否改為java.sql.Blob