views:

97

answers:

0

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... :)