title: Concurrency issues when retriveing Ids of newly inserted rows with ibatis
body: <p>I'm using iBatis/Java and Postgres 8.3.
  When I do an insert in ibatis i need the id returned.<br>
  I use the following table for describing my question:<br>
  <code>CREATE TABLE sometable ( id serial NOT NULL, somefield VARCHAR(10) );</code><br>
  The Sequence <code>sometable_id_seq</code> gets autogenerated by running the create statement.  </p>
  
  <p>At the moment i use the following sql map:</p>
  
  <pre><code>&lt;insert id="insertValue" parameterClass="string" &gt;
   INSERT INTO sometable ( somefield ) VALUES ( #value# );
   &lt;selectKey keyProperty="id" resultClass="int"&gt;
    SELECT last_value AS id FROM sometable_id_seq
   &lt;/selectKey&gt;
  &lt;/insert&gt;
  </code></pre>
  
  <p>It seems this is the ibatis way of retrieving the newly inserted id. Ibatis first runs a INSERT statement and afterwards it asks the sequence for the last id.<br>
  I have doubts that this will work with many concurrent inserts.</p>
  
  <p>Could this cause problems? Like returning the id of the wrong insert?</p>
  
  <p>( See also my related question about <a href="https://stackoverflow.com/questions/1769688/howto-return-ids-on-inserts-with-ibatis-with-returning-keyword">how to get ibatis to use the INSERT .. RETURING .. statements</a> )</p>