If you are sharing a session / connection between two threads and two of these threads are trying to execute instructions at the same time, you may see this problem.
You probably need to either (a) use the connection pool, or (b) synchronize all your access to the database.
e.g. for option (b)
put a synchronize token infront of your method to make it thread safe
Just a thought, because I donβt know that you are executing the execution context
source share