开发者

jdbctemplate and optimistic locking

开发者 https://www.devze.com 2023-01-01 10:58 出处:网络
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 versi

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, Str开发者_如何学Cing 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... :)


Nope, you'll have to add the optimistic locking behavior to your update queries manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消