0 0

hibernate4 存blob session.flush 报错0

不知道什么原因,或者哪写错了。
SessionFactory sf = sessionFactory;
Session session = sf.openSession();

LobHelper lobHelper = session.getLobHelper();
z.setWj(lobHelper.createBlob(new byte [100]));
session.beginTransaction();
session.save(z);
session.flush();
session.refresh(z, LockMode.UPGRADE); 


oracle.sql.BLOB blob=(oracle.sql.BLOB)z.getWj();
OutputStream out=blob. getBinaryOutputStream(); 
FileInputStream imgis=new FileInputStream("d://1111111111111.jpg"); 
byte[] buf=new byte[10240];//10K 缓存 
int len; 
while((len=imgis.read(buf))>0){ 
   out.write(buf,0,len); 

imgis.close(); 
out.close(); 
// 向Clob写入实际内容 
session.save(z); 
session.beginTransaction().commit(); 

———————————————————————————————————
org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl]HHH000010: On release of batch it still contained JDBC statements
[org.hibernate.engine.jdbc.spi.SqlExceptionHelper]SQL Error: 0, SQLState: null
[org.hibernate.engine.jdbc.spi.SqlExceptionHelper]Error
org.hibernate.exception.GenericJDBCException: could not insert: [com.tonbu.ORM.TbYwJcxx]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3499)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)

at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1233)
at com.tonbu.service.impl.JXCCServiceImpl.add(JXCCServiceImpl.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:73)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy12.add(Unknown Source)
at com.tonbu.action.jy.JYAction.add(JYAction.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
at com.tonbu.interceptor.AuthInterceptor.doIntercept(AuthInterceptor.java:40)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.tonbu.interceptor.EncodingInterceptor.intercept(EncodingInterceptor.java:38)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)

at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: Error
at com.alibaba.druid.pool.DruidDataSource.handleConnectionException(DruidDataSource.java:1116)
at com.alibaba.druid.pool.DruidPooledConnection.handleException(DruidPooledConnection.java:127)
at com.alibaba.druid.pool.DruidPooledStatement.checkException(DruidPooledStatement.java:68)

at com.alibaba.druid.pool.DruidPooledPreparedStatement.setBinaryStream(DruidPooledPreparedStatement.java:816)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$5$1.doBind(BlobTypeDescriptor.java:133)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$2$1.doBind(BlobTypeDescriptor.java:90)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2777)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3055)
... 105 more
Caused by: java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatementWrapper.setBinaryStream(ILjava/io/InputStream;J)V
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setBinaryStream(FilterChainImpl.java:3165)

at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setBinaryStream(FilterAdapter.java:1133)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setBinaryStream(FilterChainImpl.java:3162)
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setBinaryStream(PreparedStatementProxyImpl.java:211)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.setBinaryStream(DruidPooledPreparedStatement.java:814)
... 113 more
[com.alibaba.druid.pool.DruidDataSource]get/close not same thread
[com.alibaba.druid.pool.DruidDataSource]abandon connection, open stackTrace
2014年1月22日 10:50

2个答案 按时间排序 按投票排序

0 0

楼主,不要用对应的字段不要用Blob类型,直接用byte[]数组就非常简单了。只要把对应文件的字节数组存放到对应对象里面就可以直接save了。非常方便!

2015年12月23日 13:41
0 0

请问这个问题解决了吗?

2015年12月07日 10:25

相关推荐

    Blob.js和Export2Excel.js

    Blob.js和Export2Excel.js是两个在前端实现数据导出至Excel文件的JavaScript库。它们在Web应用中常用于提供用户一个便捷的方式,将网页上的数据下载为结构化的Excel文件,便于存储或进一步处理。 首先,Blob.js是...

    Hibernate对BLOB CLOB操作

    在Java的持久化框架Hibernate中,BLOB和CLOB是用来处理大数据对象(Binary Large Object和Character Large Object)的。这两个类型常用于存储图像、视频、大文本等数据,因为它们可以容纳超过数据库标准列大小限制的...

    Struts2 Hibernate存取Oracle数据库中的BLOB数据.pdf

    在实际操作中,可以通过Hibernate实现Oracle数据库中BLOB数据的存储和删除操作,然后利用Struts2框架展示这些BLOB数据。这样的结合,不仅可以提高开发效率,还能保证应用的性能和稳定性。 ### 实际操作步骤 在实际...

    关于在Hibernate中对于Clob,Blob字段的处理方法

    例如,当你调用`session.saveOrUpdate(entity)`或`entityManager.persist(entity)`时,Hibernate会将Clob和Blob的内容正确地保存到数据库中。 当从数据库中检索这些字段时,同样可以通过Hibernate的API获取。例如,...

    Hibernate对Blob,Clob的操作

    InputStream is = blob.getBinaryStream(); // 处理输入流,例如写入文件 Clob clob = entity.getTextData(); Reader reader = clob.getCharacterStream(); // 读取字符流,例如转换为字符串 ``` 值得注意的是,...

    Blob.js-master Blob js 插件,有时候IE不支持Blob,需要我们自己下载Blob插件,有需要小伙伴可以下载

    这个压缩包可能包含了Blob.js库的源代码,开发者可以通过查看源码来了解其内部工作原理,或者直接引用其中的Blob.js文件以在项目中使用。 Blob.js的核心功能包括: 1. 创建Blob:通过将字符串、ArrayBuffer或其他...

    Blob.js免费下载、Blob免费下载

    文件名:Blob.js,免费下载,可以使用此js在前端导出xlsx表格数据

    使用JDBC和Hibernate来写入Blob型数据到Oracle中

    在Hibernate中,Blob数据可以被映射到类的属性上,通过Session对象的save()或saveOrUpdate()方法进行保存。 首先,你需要在Hibernate配置文件(hibernate.cfg.xml)中配置Oracle数据库的连接信息。然后,在实体类中...

    hibernate对Blob类型字段进行数据添加.txt

    ### Hibernate 对 Blob 类型字段进行数据添加 #### 知识点概述 在处理数据库操作时,经常需要存储二进制大对象(Binary Large Object,简称 BLOB),例如图像、视频等非文本数据。BLOB 类型是数据库系统中用于存储...

    Hibernate读取blob字段

    在Java的持久化框架Hibernate中,Blob类型常用于存储大对象(Large Object),如图片、音频、视频或大型文本文件等。本篇文章将深入探讨如何使用Hibernate读取数据库中的Blob字段,以及涉及到的相关知识点。 首先,...

    Blob.js和 Export2Excel.js.zip

    4. **触发下载**:最后,使用Blob.js生成的URL,通过HTML5的`a`标签的`download`属性触发文件下载,用户就可以在浏览器中保存Excel文件了。 **使用示例** 使用Blob.js和Export2Excel.js时,你需要在HTML页面中引入...

    Blob.js和Export2Excel.js.rar

    4. 使用Blob.js创建一个URL引用这个Blob对象,并创建一个`a`标签模拟下载链接。设置`a`标签的`href`属性为Blob对象的URL,`download`属性为文件名,然后触发点击事件,这样浏览器就会开始下载文件。 5. 最后,记得...

    hibernate-annotations-3.4.0.GA.rar

    《Hibernate注解3.4.0.GA版详解》 Hibernate作为Java领域中的一款主流对象关系映射(ORM)框架,极大地简化了数据库操作。在3.4.0.GA版本中,它引入了注解功能,使得Java实体类与数据库表之间的映射变得更加简洁、...

    Blob.js&Export2Excel;.js

    这里,我们将深入探讨如何利用Blob.js和Export2Excel.js这两个JavaScript库来实现这个功能。 首先,Blob.js是一个JavaScript库,它提供了在浏览器端创建Blob对象的能力。Blob对象在Web API中被用来表示不可变的原始...

    Hiberante读取BLOB数据类型.

    blob.setBinaryStream(fis); document.setContent(blob); session.update(document); fis.close(); tempFile.delete(); ``` 4. **性能优化** - 使用流操作:避免一次性加载整个BLOB到内存,而是采用流式...

    f4: Facebook’s Warm BLOB Storage System

    use a specialized warm BLOB storage system, f4. f4 is a new system that lowers the effective-replication-factor of warm BLOBs while remaining fault tolerant and able to support the lower throughput ...

    Blob.js 和Export2Excel.js

    而当我们需要在Vue项目中处理数据导出,特别是导出到Excel格式时,`Blob.js`和`Export2Excel.js`两个库就显得尤为重要。这两个库帮助开发者能够方便地将前端数据转换为Excel文件,供用户下载。 `Blob.js` 是一个...

    Export2Excel和blob_vue_excel操作js

    Export2Excel和blob_vue_excel操作js 报错:script-loader!vendor/Blob in ./src/vendor/Export2Excel.js 是找不到路径的问题 解决方案:修改为script-loader!@/vendor/Blob 就可以了

    如何在GridView中显示SQL Server 2005数据库表BLOB数据.pdf

    如何在GridView中显示SQL Server 2005数据库表BLOB数据.pdf

Global site tag (gtag.js) - Google Analytics