I am trying to conceive it a website selling books online with architecture Struts2-Spring-JPA / Hibernate.
I confronted the problem of negative stock .. I explain:
When two customers require almost the same time a product of a quantity x, an audit is triggered to check if the stock available is greater than or equal to the amount requested. If two control the quantity x (and possibly purchase) happen at the same moment, it is obvious that one of the clients will exhaust the quantity x before the other, which leads to the problem of negative stock for the second customer.
So I thought to force the application to force the existence of a single instance of every book at a given time for access to its stock available at time t. (Mutual exclusion)
Suffice it to add the attribute in the declaration of singleton bean Action (Class business processing defined in applicationContext.xml) with additional treatment in the method for pool access?
There are another solution?
Thank you in advance for your help.