Syrine Chouchène
Syrine Chouchène

Reputation: 21

Managing transactions, spring boot

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

Answers (1)

itstata
itstata

Reputation: 1168

  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.

  2. 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

Related Questions