Using Spring's KeyHolder with programmatically-generated primary keys

Posted by smayers81 on Stack Overflow See other posts from Stack Overflow or by smayers81
Published on 2010-05-12T14:05:06Z Indexed on 2010/05/12 18:34 UTC
Read the original article Hit count: 379

Hello, I am using Spring's NamedParameterJdbcTemplate to perform an insert into a table. The table uses a NEXTVAL on a sequence to obtain the primary key. I then want this generated ID to be passed back to me. I am using Spring's KeyHolder implementation like this:

KeyHolder key = new GeneratedKeyHolder();
jdbcTemplate.update(Constants.INSERT_ORDER_STATEMENT, params, key);

However, when I run this statement, I am getting:

org.springframework.dao.DataRetrievalFailureException: The generated key is not of a supported numeric type. Unable to cast [oracle.sql.ROWID] to [java.lang.Number]
    at org.springframework.jdbc.support.GeneratedKeyHolder.getKey(GeneratedKeyHolder.java:73)

Any ideas what I am missing?

© Stack Overflow or respective owner

Related posts about oracle10g

Related posts about spring