简体   繁体   English

春天的事务管理的JdbcTemplate

[英]spring transaction management with jdbctemplate

I am running a java project using jdbctemplate in which update of 2000 records is happening with batch size of 500 records. 我使用的JdbcTemplate中的2000条记录更新与500条记录批量大小发生运行一个Java项目。

Since, i am using single update query would there improvement in application if i would use spring transaction management ? 因为,我使用单个更新查询将有改善应用程序,如果我会用Spring事务管理?

As per my knowledge it would help in the performance as code is going to hit the database only once 按我所知,这将有助于在性能,代码将访问数据库只有一次

even I would suggest to use 即使我建议使用

@Override
public <S extends Classname> Iterable<S> save(Iterable<S> arg0);

Which save the entities present in list directly to database without using either jdbcTemplate or transaction management 无需使用jdbcTemplate或事务管理即可将列表中存在的实体直接保存到数据库中

this is decided by your requirement. 这取决于您的要求。 if 2000 records must constants,so you have to use transaction management,if not , you can deal one record every time. 如果2000条记录必须为常量,则必须使用事务管理;如果不是,则每次可以处理一条记录。

It can definitely help you. 它绝对可以帮助您。 You can make the 500 record batch calls one by one in a Java method annotated with @Transactional annotation. 您可以在使用@Transactional批注的Java方法中一一进行500条记录批处理调用。 That way, spring will roll back the whole operation in the event that any of the update fails. 这样,如果任何更新失败,spring将回滚整个操作。

PS: I haven't specified any XML configurations where you have to specify your transaction manager. PS:我没有指定必须指定事务管理器的任何XML配置。 You can add a suitable one meeting your needs. 您可以添加一个满足您需求的产品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM