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.
I would like to expose my problem.
I created a web application with JSF technology, which interfaces with SQL Server 2005.
The application is quite simple, provides an initial login and allows the logged users to enter
data in the database, such as a new record in a table .
The problem arises when I make the calculation of the ID, which is the primary key of the new
record to insert: as increasing of users logged so grows the probability that two users simultaneously
attempt to insert a new record with the same ID with the problem of violation of the primary key.
Now as the number of users logged each have a different instance of the application, the problem is
unsolvable, and correct me if I'm wrong, if I continue to leave the method of calculation of the ID
in the application itself, such as Session.
I thave to move the metod to the application server as a service (I use Tomcat)? How?
Is there any tool already developed?
SQL Server does not support sequences. It does however support identity columns. If you are happy enough to tightly couple your application to SQL Server you can use them. Alternatively, if you want it to remain database agnostic, you can use a pattern like the HiLo pattern.
Joined: Dec 14, 2010
Unfortunately I don't decide for DB and I have to use
What are identity columns?