This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There is a need to get the correct id value from the database(sql express 2005) after an insert,update,delete function.This value should exactly reflect in the database once insert or update or delete functions are carried out.for eg.; if I have 5 records in the database and I do a insert it should reflect 6th row with values. On the other hand if I am deleting the record(6th row) and again try to insert values it should get inserted for 6th row only and not for the 7th row(as it happens now).
What is the Identity specification that you have given for the DB table ? You need to change it from Auto Generated to an insertable Identity(in your hbm or model class).
Now from your java code before you do any operation, you can get the max id for this table from DB, increment it by one and then set it explicitly in your Java code. In this way you control the ID column value from the code instead of relying on the SQl server.
We are using select ident_current('table_name') to get the max id. The id column is identity column. now if i delete the 5th id then it should delete the 5th id in sql server and send us the 6th row as the id.but it is sending us 5th id only.Since it is an identity column we expect server to keep the id and increment accordingly.