V
V
Volokoron2021-01-22 15:06:05
PostgreSQL
Volokoron, 2021-01-22 15:06:05

How to manage transactions in spring data?

Good day!
I am doing a training project spring boot + spring data + postgresql. Airline booking. To exclude the possibility of buying extra tickets, I created a table in which there is information about the remaining number of tickets not sold. Instead of using the Serializable isolation level, I want to lock only the row via FOR UPDATE and @Lock(LockModeType.PESSIMISTIC_WRITE). But how to make sure that the transaction is not committed until the payment is confirmed or within a specified time if the payment has not gone through.
Or what approach generally to use in the given situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2021-01-22
@Volokoron

It is not necessary to do it through transactions.
For each "purchase" you create an application in a separate table "booking".
Upon receipt of payment, you sell the ticket, delete the entry from the applications.
With a certain frequency, you go through this table, delete obsolete applications.
Here, yes - we do everything in a transaction.
Accordingly, when calculating the number of available tickets, you count as NUMBER_TICKETS - NUMBER_APPLICATIONS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question