-1
我的實體類是:節約一滴到數據庫使用的彈簧 - 休眠
@Entity
@Table (name = "rs_production_dump")
public class ProdDumpBLOB implements Serializable{
/**
* the 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*/
}
和保存BLOB DAO層的方法如下:
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();
}
}
我試圖保存Excel文件爲Blob。輸入的FileInputStream對象被創建,並通過使用POI庫創建一個Excel文件後如下:
File xlsfile = new File(fileName);
FileInputStream fis = new FileInputStream(xlsfile);
我休眠-config.xml中與映射會話獲取&春天-config.xml中是實體更新如下:
<bean id="prodDumpBlobDaoImpl" class="com.comp.ecmrs.dao.impl.ProdDumpBLOBDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
我想這應該做的伎倆但我仍然在我的日誌中收到此錯誤:
10:48:55.670 [main] DEBUG org.hibernate.internal.util.EntityPrinter - com.comp.ecmrs.dao.entity.ProdDumpBLOB{ [email protected], reportName=PROD-DUMP, mimeType=application/vnd.ms-excel}
10:48:55.686 [main] DEBUG org.hibernate.SQL - insert into 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
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$5$1.doBind(BlobTypeDescriptor.java:133) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$2$1.doBind(BlobTypeDescriptor.java:90) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:93) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2786) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3064) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:364) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:356) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:277) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final]
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558) ~[spring-orm-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at com.sun.proxy.$Proxy47.saveProdDumpBLOB(Unknown Source) [na:na]
at com.comp.ecmrs.service.ReportServiceImpl.getProductionDumpReportData(ReportServiceImpl.java:417) [classes/:na]
at com.comp.ecmrs.test.ProductionDumpTest.testGetProdReportData(ProductionDumpTest.java:53) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80-ea]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80-ea]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80-ea]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80-ea]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) [junit.jar:na]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit.jar:na]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) [junit.jar:na]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit.jar:na]
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:81) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) [junit.jar:na]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit.jar:na]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit.jar:na]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit.jar:na]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit.jar:na]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) [junit.jar:na]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) [junit.jar:na]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162) [spring-test-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) [.cp/:na]
at 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 back 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 back
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>
你using.Please什麼版本DBCP共享你的Maven文件 – shankarsh15
您好,請找我的pom.xml文件的片斷作爲....可見它是1.2.2版本 \t \t \t 公地DBCP \t \t \t 公地DBCP \t \t \t 1.2.2 \t \t \t \t \t \t \t \t \t \t \t \t commons-pool的 \t \t \t \t \t commons-pool的 \t \t \t \t \t \t \t \t \t \t \t \t \t \t com.thoughtworks.xstream \t \t \t XStream的 \t \t \t 1.4.3 \t \t –
@ParulChauhan我已經添加代碼到您的來自你的評論的問題。今後,請對原始帖子進行更改/編輯,而不是使用註釋以提高可讀性。 – Lucky