0

I have a JAX-RS (RESTEasy) endpoint. Within the endpoint method I am checking a database timestamp column for a JPA entity and if the column is null then I save the current time, raise an alert and return success, if the column already has a time set then I do nothing and return success.

Now I am finding that if the endpoint is called 5/6 times in quick succession (within the same 500ms) then every request is seeing the column as null and I get 5/6 alerts raised where I only wanted one.

I assume this is because the requests are processed asynchronously and the database changes have not been fully committed until after the last request.

Is it possible to force the server to process requests for this endpoint synchronously? So that they are queued and only processed when all transactions have been committed? If not is there a better solution to this problem?

DaveB
  • 2,953
  • 7
  • 38
  • 60
  • You'd need to synchronize the read in a transaction as well. I'm not a JPA expert, but you might need to look at your implementations documentation. What JPA implementation are you using? – James R. Perkins Jul 18 '23 at 21:40
  • We're using Hibernate / JPA 2.2, its a Jakarta EE 8 stack – DaveB Jul 19 '23 at 06:44
  • This is for Jakarta EE 10, but it should still be relevant. Have a look at the lock mode https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/lockmodetype. – James R. Perkins Jul 19 '23 at 19:37

0 Answers0