I have created a table in MSSQL having following structure –
**Table Name - TestTable**
id (int) (Primary key)
name (varchar)
owner (varchar)
I have given Identity specification for column ‘id’ with auto increment with 1 for each new row. When I created iBatis artifacts for TestTable, the insert function is getting generated, in the DAO, with following signature –
void insert(TestTable record);
I want the insert function to return the newly generated ‘id’ for that row, instead of void.
How to achieve this?
In your ibatis SqlMap file, add the following:
Or you could replace Select Scope_identity with another SQL query designed to return the last identity column inserted. The Scope_identity is specific to MS SQL (as requested in the question).