java - saving blob into DB using spring - hibernate -


my entity class :

@entity @table (name = "rs_production_dump") public class proddumpblob implements serializable{     /**      * serial version id.      */     private static final long serialversionuid = -3395282616292841663l;      @column(name = "report_name")     protected string reportname;      @column(name = "report")     protected blob report;      @column(name = "mime_type")     protected string mimetype ;     /* getters & setters*/     } 

and dao layer method saving blob follows:

public void saveproddumpblob(proddumpblob produmpblob, fileinputstream fis, long filelength){      try {          loggerutil.infoapplicationlog(".... inside saveproddumpblob ...." + sessionfactory);          session session = this.sessionfactory.getcurrentsession();          blob blob1 = hibernate.getlobcreator(session).createblob(fis,filelength);          produmpblob.setreport(blob1);          session.save(produmpblob);          loggerutil.infoapplicationlog(".... exiting saveproddumpblob ....");     }      catch (exception e) {         loggerutil.errorapplicationlog("error : proddumpblobdaoimpl:saveproddumpblob. #error message: " + e.getmessage(), e);         e.printstacktrace();     } } 

i'm trying save excel file blob. input fileinputstream object has been created , passed on follows after creating excel file using poi library:

file xlsfile = new file(filename); fileinputstream fis = new fileinputstream(xlsfile); 

my hibernate-config.xml updated entity mapped session fetching & spring-config.xml follows:

<bean id="proddumpblobdaoimpl" class="com.comp.ecmrs.dao.impl.proddumpblobdaoimpl">         <property name="sessionfactory" ref="sessionfactory" />     </bean> 

i think should trick i'm still getting error in logs:

10:48:55.670 [main] debug org.hibernate.internal.util.entityprinter - com.comp.ecmrs.dao.entity.proddumpblob{ report=org.hibernate.engine.jdbc.blobproxy@465361b6, reportname=prod-dump, mimetype=application/vnd.ms-excel} 10:48:55.686 [main] debug org.hibernate.sql - insert report.rs_production_dump (mime_type, report, report_name) values ( ?, ?, ?) 10:48:55.701 [main] debug org.springframework.orm.hibernate4.hibernatetransactionmanager - initiating transaction rollback after commit exception java.lang.abstractmethoderror: org.apache.commons.dbcp.delegatingpreparedstatement.setbinarystream(iljava/io/inputstream;j)v     @ org.hibernate.type.descriptor.sql.blobtypedescriptor$5$1.dobind(blobtypedescriptor.java:133) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.type.descriptor.sql.blobtypedescriptor$2$1.dobind(blobtypedescriptor.java:90) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.type.descriptor.sql.basicbinder.bind(basicbinder.java:93) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.type.abstractstandardbasictype.nullsafeset(abstractstandardbasictype.java:280) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.type.abstractstandardbasictype.nullsafeset(abstractstandardbasictype.java:275) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.type.abstractsinglecolumnstandardbasictype.nullsafeset(abstractsinglecolumnstandardbasictype.java:57) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.persister.entity.abstractentitypersister.dehydrate(abstractentitypersister.java:2786) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:3064) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:3509) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.action.internal.entityinsertaction.execute(entityinsertaction.java:88) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.engine.spi.actionqueue.execute(actionqueue.java:364) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.engine.spi.actionqueue.executeactions(actionqueue.java:356) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.engine.spi.actionqueue.executeactions(actionqueue.java:277) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.event.internal.abstractflushingeventlistener.performexecutions(abstractflushingeventlistener.java:328) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.event.internal.defaultflusheventlistener.onflush(defaultflusheventlistener.java:52) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.internal.sessionimpl.flush(sessionimpl.java:1234) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.internal.sessionimpl.managedflush(sessionimpl.java:404) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.engine.transaction.internal.jdbc.jdbctransaction.beforetransactioncommit(jdbctransaction.java:101) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.hibernate.engine.transaction.spi.abstracttransactionimpl.commit(abstracttransactionimpl.java:175) ~[hibernate-core-4.2.1.final.jar:4.2.1.final]     @ org.springframework.orm.hibernate4.hibernatetransactionmanager.docommit(hibernatetransactionmanager.java:558) ~[spring-orm-4.1.0.release.jar:4.1.0.release]     @ org.springframework.transaction.support.abstractplatformtransactionmanager.processcommit(abstractplatformtransactionmanager.java:755) [spring-tx-3.2.8.release.jar:3.2.8.release]     @ org.springframework.transaction.support.abstractplatformtransactionmanager.commit(abstractplatformtransactionmanager.java:724) [spring-tx-3.2.8.release.jar:3.2.8.release]     @ org.springframework.transaction.interceptor.transactionaspectsupport.committransactionafterreturning(transactionaspectsupport.java:475) [spring-tx-3.2.8.release.jar:3.2.8.release]     @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:270) [spring-tx-3.2.8.release.jar:3.2.8.release]     @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:94) [spring-tx-3.2.8.release.jar:3.2.8.release]     @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) [spring-aop-3.2.8.release.jar:3.2.8.release]     @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:204) [spring-aop-3.2.8.release.jar:3.2.8.release]     @ com.sun.proxy.$proxy47.saveproddumpblob(unknown source) [na:na]     @ com.comp.ecmrs.service.reportserviceimpl.getproductiondumpreportdata(reportserviceimpl.java:417) [classes/:na]     @ com.comp.ecmrs.test.productiondumptest.testgetprodreportdata(productiondumptest.java:53) [test-classes/:na]     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:1.7.0_80-ea]     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) ~[na:1.7.0_80-ea]     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:1.7.0_80-ea]     @ java.lang.reflect.method.invoke(method.java:606) ~[na:1.7.0_80-ea]     @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47) [junit.jar:na]     @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) [junit.jar:na]     @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44) [junit.jar:na]     @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) [junit.jar:na]     @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:72) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:81) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:72) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.junit.runners.parentrunner.runleaf(parentrunner.java:271) [junit.jar:na]     @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:216) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:82) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.junit.runners.parentrunner$3.run(parentrunner.java:238) [junit.jar:na]     @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63) [junit.jar:na]     @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236) [junit.jar:na]     @ org.junit.runners.parentrunner.access$000(parentrunner.java:53) [junit.jar:na]     @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229) [junit.jar:na]     @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:60) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:67) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.junit.runners.parentrunner.run(parentrunner.java:309) [junit.jar:na]     @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:162) [spring-test-4.1.0.release.jar:4.1.0.release]     @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) [.cp/:na]     @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) [.cp/:na]     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467) [.cp/:na]     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683) [.cp/:na]     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390) [.cp/:na]     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) [.cp/:na] 10:48:55.701 [main] debug org.springframework.orm.hibernate4.hibernatetransactionmanager - rolling hibernate transaction on session [sessionimpl(persistencecontext[entitykeys=[entitykey[com.comp.ecmrs.dao.entity.proddumpblob#pld_95103016]],collectionkeys=[]];actionqueue[insertions=[entityinsertaction[com.comp.ecmrs.dao.entity.proddumpblob#pld_95103016]] updates=[] deletions=[] collectioncreations=[] collectionremovals=[] collectionupdates=[] unresolvedinsertdependencies=unresolvedentityinsertactions[]])] 10:48:55.701 [main] debug org.hibernate.engine.transaction.spi.abstracttransactionimpl - rolling 10:48:55.701 [main] debug org.hibernate.engine.transaction.internal.jdbc.jdbctransaction - rolled jdbc connection 10:48:55.701 [main] debug org.hibernate.engine.transaction.internal.jdbc.jdbctransaction - re-enabling autocommit 10:48:55.701 [main] debug org.springframework.orm.hibernate4.hibernatetransactionmanager - closing hibernate session [sessionimpl(persistencecontext[entitykeys=[entitykey[com.comp.ecmrs.dao.entity.proddumpblob#pld_95103016]],collectionkeys=[]];actionqueue[insertions=[entityinsertaction[com.comp.ecmrs.dao.entity.proddumpblob#pld_95103016]] updates=[] deletions=[] collectioncreations=[] collectionremovals=[] collectionupdates=[] unresolvedinsertdependencies=unresolvedentityinsertactions[]])] after transaction 

pom.xml

<dependency>    <groupid>commons-dbcp</groupid>    <artifactid>commons-dbcp</artifactid>    <version>1.2.2</version>    <exclusions>       <exclusion>          <groupid>commons-pool</groupid>          <artifactid>commons-pool</artifactid>       </exclusion>    </exclusions> </dependency> <dependency>    <groupid>com.thoughtworks.xstream</groupid>    <artifactid>xstream</artifactid>    <version>1.4.3</version> </dependency> 

try using dbcp version 1.4 has jdbc 4 support.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -