Any one have idea how to generate id
starting from 1 so that the next object has 2 and so on?
I have trying the following but dose not work:
<
A common solution to generating a sequential id is to use a database. Most databases have a built-in way do this. For example, IDENTITY
in SQL Server or AUTO_INCREMENT
in MySQL.
Consider using a persistence framework like Hibernate and you can declare one of many proven strategies like identity, hilo or uuid some of which are sequential and some aren't. Some are generated by the application and some by the database but the trade-offs are well documented and you'll know what you're getting yourself into.