title: How can two rows be written atomically when one row has a foreign key into the other?
body: <p>I have a transaction where we insert a row of table <code>foo</code> and then a row of table <code>bar</code>. This ensures we either write both rows or neither. The trouble with this is <code>bar</code> has a foreign key into <code>foo</code>. Because we don't know the <code>id</code> of <code>foo</code> at the time of the <code>bar</code> insert, this fails the foreign key constraint.</p>
  
  <p>Previously I've used tools like SQLAlchemy, when writing Python backends, that include the capability of flushing a session before the transaction is committed--this allows the user to derive the <code>id</code> of <code>foo</code> and pass it along to the <code>INSERT</code> into <code>bar</code> before actually writing anything.</p>
  
  <p>My question is, in the context of JDBC and its Clojure wrapper, how can this be done?</p>