I would like generate userid base on their country and state. Like if the country is USA and state is Michigan, and she's the first user, then the userid will be USMI0001. The subsequent will be USMI0002. But b4 I insert into database, I need to do a select count to check no. of user then I can put in the digits behing the userid. This will have a conflict because other session may also doing the same thing. This might end up same 4 digits behind the userid. Is ter any function in Spring that can overcome this conflict?
Use a database sequence to generate the next number. Many databases, such as Oracle, support this. Note that it is usually a bad idea to include any information in the ID, as that information may change over the course of time.
So u mean just leave it 1.....1000 ?
1. if you need an incrementer for each state (to be unique for each) then make a sequence for each in db.
2. use unique index for not allowing dupes, and try to use int (seq) pk (surrogate key). (making it easier to use O/R tool like hibernate / JDO)