如何儲(chǔ)存blob對(duì)象在sql server?實(shí)體set blob對(duì)象保存就報(bào)錯(cuò),不set blob對(duì)象就沒問題
@Test ????public?void?writeBlob()?throws?Exception{ ????????Students?s=new?Students(1,?"張學(xué)友",?"男",?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
這一般都是導(dǎo)包的問題,你檢查下你導(dǎo)入的包文件一不一致
2017-01-09
查看一下你的數(shù)據(jù)庫中圖片字段對(duì)應(yīng)的數(shù)據(jù)類型是否設(shè)為blob,我是這個(gè)原因。
2017-01-06
留意一下bean包中的持久化類的對(duì)應(yīng)數(shù)據(jù)類型是否修改為Blob ?還有對(duì)應(yīng)的hbm.xml里面 列的property的type也是否改為java.sql.Blob