Reputation: 21
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?
Upvotes: 0
Views: 251
Reputation: 1168
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
Upvotes: 1