我正在尝试实现批量写入以提高特定代码的性能。现在我已经编写了测试用例,看看当我打开 eclipse 链接中的批处理写入时会发生什么。从日志看来,正在为每个插入语句创建批处理,这不是我所期望的。下面是测试用例
@Test
public void test_batchCreateRouters(){
List<RouterDTO> routerDTOList = new ArrayList<RouterDTO>();
IRouterService iRouterService = (IRouterService) ctx.getBean("routerService");
build_DTO("Test8",routerDTOList);
build_DTO("Test2",routerDTOList);
build_DTO("Test3",routerDTOList);
build_DTO("Test4",routerDTOList);
build_DTO("Test5",routerDTOList);
build_DTO("Test6",routerDTOList);
build_DTO("Test7",routerDTOList);
for(RouterDTO routerDTO:routerDTOList) {
iRouterService.createRouter(routerDTO);
}
}
build_DTO 只是填充 DTO 并将其添加到列表 createRouter 将进行一些验证并执行以下代码:
try {
getJpaTemplate().persist(entity);
} catch (RuntimeException re) {
throw re;}.
但是当我检查日志时,我得到如下所示,它表明对于每个插入,都会创建新批次。有人对此有任何想法,或者可以将我带到正确的地方。
[EL Finest]: 2012-09-18 11:55:56.218--ServerSession(598639019)--Connection(1572163248)--Thread(Thread[main,5,main])--从连接池获取的连接[默认] . [EL Finer]: 2012-09-18 11:55:56.218--ClientSession(1274943796)--Connection(1572163248)--Thread(Thread[main,5,main])--开始交易 [EL Finer]: 2012 -09-18 11:55:56.219--ClientSession(1274943796)--Connection(1572163248)--Thread(Thread[main,5,main])--开始批处理语句[EL Fine]: 2012-09-18 11 :55:56.22--ClientSession(1274943796)--Connection(1572163248)--Thread(Thread[main,5,main])--INSERT INTO ROUTER_QUANTITY (ROUTER_QUANTITY_ID, ROUTER_PERIOD_ID, COMMENTS, CONTRACT_ID, COUNTER_PARTY, CREATED_BY, CREATED_ON, FACILITY , LAST_UPDATED_BY, LAST_UPDATED_ON, MODIFIED, QUANTITY, QUANTITY_TEMPLATE_ID, SERVICE_ID, SOURCE, STATUS) 值 (?, ?, ?, 5--ServerSession(598639019)--Connection(1572163248)--Thread(Thread[main,5,main])--连接释放到连接池[默认]。[EL Finer]: 2012-09-18 11:55:56.5--UnitOfWork(233788733)--Thread(Thread[main,5,main])--结束工作单元提交 [EL Finer]: 2012-09- 18 11:55:56.5--UnitOfWork(233788733)--Thread(Thread[main,5,main])--恢复工作单元[EL Finer]: 2012-09-18 11:55:56.501--UnitOfWork( 233788733)--Thread(Thread[main,5,main])--发布工作单元[EL Finer]: 2012-09-18 11:55:56.501--ClientSession(1274943796)--Thread(Thread[main, 5,main])--客户端发布[EL Finer]: 2012-09-18 11:55:56.502--ServerSession(598639019)--Thread(Thread[main,5,main])--客户端获取:1625102195 [ EL Finer]: 2012-09-18 11:55:56.502--ClientSession(1625102195)--Thread(Thread[main,5,main])--获取工作单元:1395568819 [EL Finest]:2012-09-18 11:55:56.563--UnitOfWork(1395568819)--Thread(Thread[main,5,main])--persist() 操作调用:fm.am.integration。 dao.jpa.allocationquantity.AllocationQuantity@23597cac。[EL Finer]:2012-09-18 11:55:56.563--UnitOfWork(1395568819)--Thread(Thread[main,5,main])--开始工作单元刷新 [EL Finest]:2012-09- 18 11:55:56.564--UnitOfWork(1395568819)--Thread(Thread[main,5,main])--执行查询InsertObjectQuery(fm.am.integration.dao.jpa.allocationquantity.AllocationQuantity@23597cac) [EL Finest ]: 2012-09-18 11:55:56.564--ServerSession(598639019)--Connection(1572163248)--Thread(Thread[main,5,main])--从连接池获取的连接[默认]。[EL Finer]:2012-09-18 11:55:56.568--ClientSession(1625102195)--Connection(1572163248)--Thread(Thread[main,5,