简体   繁体   中英

jdbctemplate and optimistic locking

In the project I'm in Hibernate and Spring jdbctemplate are mixed. I added optimistic locking. Hibernate works great with versioning but now I have to tansform all this jdbctemplate code to use versioning too.

Is there something like LockingJdbcTemplate (like SimpleJdbcTemplate)? I was thinking I could implement a generic update method


update(String tableName, String columnsSql, String whereSql, Long version, Object... params)

Where I could:

  • append version=version+1 to columnSql
  • append version=? to whereSql
  • add version number to correct place within params (separate param is forcing to pass that value)
  • Check that exactly 1 item was updated and throw StaleObjectStateException otherwise

Is there any library that would wrap jdbctemplate and do something similar for me? Don't want to invent something that exists... :)

不,您必须手动将乐观锁定行为添加到更新查询中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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