title: Spring JdbcTemplate Cannot Get Insert ID from MySQL
body: <p>I am trying to insert a row into a MySQL table and get it's insert ID. I am aware of the MySQL <code>last_insert_id()</code> function, I just cannot seem to get it to work. Currently, I am trying to use a function annotated as a transaction and I am only getting 0 returned. I am using Spring 3.1.</p>
  
  <pre><code>    @Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
      private long insertTransactionRecord 
      (
          int custID, 
          int porID, 
          String date, 
          short crvID
      ) {
          m_template.update ("INSERT INTO " +
                             "    transaction " +
                             "( " +
                             "    por_id, " +
                             "    cust_id, " +
                             "    trans_date, " +
                             "    crv_id " +
                             ") " +
                             "VALUES " +
                             "( " +
                             "    ?, " +
                             "    ?, " +
                             "    ?, " +
                             "    ? " +
                             ")",
                             new Object[] {
                                 porID,
                                 custID,
                                 date,
                                 crvID
                             });
          return m_template.queryForLong ("SELECT " +
                                          "    last_insert_id() " +
                                          "FROM " +
                                          "    transaction " +
                                          "LIMIT 1");
      }
  </code></pre>