Use manaual sql-transaction to prevent deadlocks

Also select the forUpdate on the base table, instead of the version
table. Using the version table will result in more deadlocks (due to
inserts instead of updates).