Will @Transactional cause batch updates with jdbcTemplate if used in a loop?

╄→尐↘猪︶ㄣ 提交于 2020-12-15 00:44:32

问题


I wanted to do batch updates using Springs JDBC template in postgre.

However, I am curious that do I really need to use the jdbcTemplate.BatchUpdate() calls. I read in several places that they are slower if not implemented correctly.

Will adding a @Transactional on the method that inserts in a loop achieve the same functionality of batching the updates?

If the below method that inserts one record at a time, is called from a loop which is in a transactional as shown, will this cause updates to happen in a batched fashion?

public void insertProdPayload(String Prod_Name, LocalDate sourceDt, String exchangeId, int status, String payload) {
    int ret = jdbcTemplate
            .update(DBQueryConstants.INSERT_PAYLOAD, Prod_Name, sourceDt, exId, status, payload);
   
}

@Override
@Transactional
public void ingestListOfPayloads(List<Message<MessageMetricRecord>> payloadMessages) {
    for (Message<Payload> message : payloadMessages) {
    insertProdPayload(message.getProdName,message.getDate(),message.getExchangeID(),message.getStatus(),message.getPayload());
}
}

The jdbc template has default config of SpringBoot 2 and PostGreSql version is 9.6.

来源:https://stackoverflow.com/questions/65062510/will-transactional-cause-batch-updates-with-jdbctemplate-if-used-in-a-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!