I have a main method which sequentially call two web-services. The first web service first insert data into request table which have a primary key that is sequentially generated using hibernate. This table also have one status field whose initial status is "Received". Then this first web service,process this request and then change the status too "Processed".
Now main method call second web-service to fetch request whose status is "Processed". As the calling from the main method is sequential, the second web-service call can have just one entry in it whose status is "Processed". After this, main method sleep for 5 second and process repeat infinitely. Also when I fetch this record I am changing the status to "completed".
Also the web-service's is accessing DB remotely. The data also consist one requestId(This is not primary key).
So the problem is when this process continue for 1 hour I see there is some inconsistency in the requestId I send and receive. These ID didn't match.
And I can see there are multiple entries whose status remain Processed
.
I was using hibernate id generator as increment but while testing this system in multiple cluster I faced uniqueConstraint exception. So I started using sequence generator, and now facing this issue.
Do I need to use flush after commit?