I have the following problem. There is a transaction, the following makes.
transaction:
- Look in the database, if an object with parameters available.
- If not, then create this object, otherwise, change the object and do update.
Suppose we have two transactions (T1 and T2) that are executed in parallel.
T1 looks at the database, there is no object. A millisecond later, T2 looks at the database, there is also no object.
T1 saves the object into the database and it also makes T2.
We have two objects in the database instead of one.
We can I solve this problem?
I'm using: Hibernate + Spring + Tomcat
Thank you.