Hi, I submitted a PR[1] to show how to use TCC with JPA. There are some missing points with my limited knowledge of JPA. So I just send out this email to ask help from community.
In the inventory service[2], we need to update the product in stock number[3]. As the reserver method could be invoked in multiple threads at the same time and JPA doesn't provide the isolation across these thread[4]. We may need to add optimis lock or use version to keep track for the change. But I didn't manage to get workable code by applying the optimic lock or using the version file to prevent the lost updates[5]. So I'm asking help from the expert of JPA for an example of this case. [1]https://github.com/apache/incubator-servicecomb-saga/pull/290 [2]https://github.com/apache/incubator-servicecomb-saga/tree/SCB-820/saga-demo/tcc-spring-demo/inventory [3]https://github.com/apache/incubator-servicecomb-saga/blob/SCB-820/saga-demo/tcc-spring-demo/inventory/src/main/java/org/apache/servicecomb/saga/demo/pack/inventory/InventoryService.java#L44 [4]https://vladmihalcea.com/a-beginners-guide-to-database-locking-and-the-lost-update-phenomena/ [5]https://vladmihalcea.com/preventing-lost-updates-in-long-conversations/ Willem Jiang Twitter: willemjiang Weibo: 姜宁willem