我的任务是使用BoneCP和jOOQ以及Spring建立一个项目,但是我遇到了一些困难.在我的MySQL数据库中单独插入可以很好地工作,但使用190,000个对象需要大约20分钟,所以为了加快速度,我想一次使用100个批量插入.但是,这会引发以下异常:
org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is java.sql.sqlException: Connection is closed!
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:288)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:849)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:826)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:496)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:266)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
at com.theshahin.service.YmsLinkDataService$$EnhancerBySpringCGLIB$$b9b6e447.create(sql.sqlException: Connection is closed!
at com.jolBox.bonecp.ConnectionHandle.checkClosed(ConnectionHandle.java:459)
at com.jolBox.bonecp.ConnectionHandle.rollback(ConnectionHandle.java:1270)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:285)
... 44 more
(值得一提的是,在第一个批处理查询时会抛出此异常,因此之前没有执行任何查询).这是我的applicationContext.xml,它基于jOOQ教程中的一个(你可以在这里找到它:http://www.jooq.org/doc/3.3/manual/getting-started/tutorials/jooq-with-spring/):
Box.bonecp.BoneCPDataSource" destroy-method="close">
sqlDialect">${jooq.sql.dialect}
这是用于将记录保存到MysqL数据库的代码. (注意:输出注释的代码是我用于单个插入的代码)
@Service
public class YmsLinkDataService extends BaseService {
@Transactional
public void create(List
这是抛出错误的测试用例(我知道它现在实际上没有测试任何东西.一旦成功保存到DB,我会这样做):
@Test
public void batchInsert() throws InterruptedException,sqlException {
int batchCount = 0;
List
任何帮助将不胜感激!
最佳答案
原文链接:https://www.f2er.com/spring/431833.html