title: Is there a way to extract primary key(or ROWID) using NamedParameterJdbcTemplate and GeneratedKeyHolder?
body: <p>I am trying to extract ROWID or the primary key using Spring's NamedParameterJdbcTemplate and GeneratedKeyHolder.</p>
  
  <p>I am trying to do something like this.</p>
  
  <pre><code>MapSqlParameterSource parameters = new MapSqlParameterSource()
                  .addValue("param1", value1)
                  .addValue("param2", value2);
  KeyHolder keyHolder = new GeneratedKeyHolder();
  namedParameterJdbcTemplate.update("INSERT INTO TABLE(ID, col1, col2)"
                  + "VALUES(TABLE.TABLE_SEQ.NEXTVAL, :param1, :param2)",
                  parameters, keyHolder);
  </code></pre>
  
  <p>After executing above query when I try to do <code>keyHolder.getKey().longValue()</code> it is throwing below exception.</p>
  
  <pre><code>HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataRetrievalFailureException: The generated key is not of a supported numeric type. Unable to cast [oracle.sql.ROWID] to [java.lang.Number]
  </code></pre>
  
  <p>When I went through this <a href="http://docs.oracle.com/cd/B28359_01/java.111/b31224/datacc.htm" rel="noreferrer">http://docs.oracle.com/cd/B28359_01/java.111/b31224/datacc.htm</a> I understand (i hope i did) that ojdbc is not mapping oracle RowId to java RowId.</p>
  
  <p>Can any one suggest is there any way to extract the key? (Yes it can be done using PreparedStatement but it is making my code bit ugly to read and manipulate on some conditions). Your suggestions are much appreciated.</p>