In my spring boot application , i want to avoid booking more than one appointment per date but when two requests of booking for a date x are done in the same time i have the two appointments saved in the database with the same date x. How to resolve this, any help please?
Asked
Active
Viewed 239 times
0
-
The answer is in your question - use a transaction. If the question is "what is a database transaction and how do I use one in Spring" I would say that that is too broad. – Boris the Spider Jan 14 '17 at 17:08
1 Answers
1
If possible do not insert the second booking (e.g. check with a query before inserting or lock the booking pessimistic). This should be the best way - there are several ways to prevent concurrent bookings. You will also find a lot of discussions on stackoverflow.
If this is not possible in your use case: Use a database constraint (this will throw an exception if booking and date is already in your database and you can handle the error in our application) https://stackoverflow.com/a/2570810/5978781