title: Spring Data pessimistic lock for creating a new Entity
body: <p>We have more applications that write a record into the DB. The record can be identified by an unique recordName (which is not ID). They can both create the same record at the same time, but I want only one record to be created. The algorithm I want to use should look somehow like this:</p>
  <pre><code>start transaction, lock the table
  check if the record with recordName is present in the table
  if not present: create row
  commit, release lock, end transaction
  </code></pre>
  <p>Is it possible to somehow use the pessimistic lock to ensure, that only one record will be created. I only found pessimistic locks to be used on Entities, not on whole tables.</p>