JdbcTemplate uses a DataSource, so it does not guarantee that you will use the same connection for the LOCK TABLE statement and everything that you are going to do the next time you call JdbcTemplate. Therefore, it is important that you do this in a transaction. Configure PlatformTransactionManager, or DataSourceTransactionManager to JDbcTemplate DataSource, or JtaTransactionManager if JdbcTemplate uses the container-supplied JNDI data source. You can annotate your method as @Transactional or create a transaction programmatically using PlatformTransactionManager.
source
share