Suppose we have a need to insert datas into 3 table, and they have this "foreign key"
relathinship.
If we provide front end 3 separate POST methods, and they submit all the data in one “submit” action. And these three methods don’t have a step by step work flow like this one
How can we ensure the transaction between the 3 controller calls?
I’ve checked eXtended Architecture, is there an alternative to do this?
For instance, we have a backend and frontend like this.
// backend
"/api/insert1"
"/api/insert2"
"/api/insert3"
// frontend
function submit(){
insert1(data1,"/api/insert1")
insert2(data2,"/api/insert2")
insert3(data3,"/api/insert3")
}
If one of the three insert actions fails, what can we do to undo them all?
If we code three extra methods to undo these, it would be a huge work consider it may actually be 100 methods in total. And there’s a chance the user close the app/page before it all finished.
If we use XA three stages we need to store the sqlsession
which also a considerable workload to server.
I feel wrong to put all these data into one POST method.