title: Upsert with a transaction
body: <p>I'm using Spring with PostgreSQL and I try to do a sort of UPSERT by using a code like this:</p>
  
  <pre><code>jt.update("delete from A where id = 1")
  jt.update("insert into A (id, value) values (1, 100)")
  </code></pre>
  
  <p>wrapped inside a transaction (using <code>@Transactional</code>).</p>
  
  <p>The problem is that, when there are many concurrent requests, this code fails with 'duplicate key' errors, meaning the transaction is not isolated, or... </p>
  
  <p>Am I missing something about how transactions work? Should I use a different mechanism here (ex. thread synchronization)?</p>