title: Hibernate: prevent duplicate inserts when processing concurrently?
body: <p>When both <code>Thread1</code> and <code>Thread2</code> are running, is it possible to prevent two <code>Foo</code> objects being saved to the database?</p>
  
  <pre><code>Thread1 {
      Foo foo = dao.getFoo("bar");
      if(foo == null) {
          foo = new Foo("bar");
          dao.save(foo);
      }
  }
  Thread2 {
      Foo foo = dao.getFoo("bar");
      if(foo == null) {
          foo = new Foo("bar");
          dao.save(foo);
      }
  }
  </code></pre>