Quantcast

CALL IDENTITY() and Spring's jdbcTemplate

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

CALL IDENTITY() and Spring's jdbcTemplate

okobloko
When calling "CALL IDENTITY()" after an "INSERT" operation, on an in-memory instance of HSQLDB, I am receiving a 0 (zero) in return :

<code>
jdbcTemplate.update("INSERT INTO firm (id,name,postcode) VALUES (?,?,?)",
                               new Object[] {null,firmName,postcode});
int lastId = jdbcTemplate.queryForInt("CALL IDENTITY();");
</code>

I can verify, however, that the correct ID is being automatically generated by HSQLDB with a follow up query that returns the correct id :

<code>
int lastId= jdbcTemplate.queryForInt("SELECT id FROM firm WHERE name = ?",new Object[]{firmName});
</code>

I have searched quite extensively and found a few other people with similar problems but no solutions. Should this be committed as a bug? Is queryForInt incorrect? Is there a problem with Spring?

Any advice gratefully received.

Ben
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CALL IDENTITY() and Spring's jdbcTemplate

spring.oracle
New connection is created with each query by JdbcTemplate. IDENTITY returns last inserted it for the _current_ connection.
Loading...