How to create data in database available for other sessions before transaction is finished in mendix 5.13.1

0
I have the following problem in Mendix 5.13.1: I have to do a fraud check using a asynchronious webservice as a part of a bigger transaction. But there is a problem that sometimes the answer of the asynchronious webservice arrives before the transaction is finished. Before calling the (consumed)webservice a record is created with a reference-key that is passed to the webservice. The transaction is not finished at this moment so this goes on. In the published webservice, that handles the reply of the fraud check, the record created with the reference-key is retrieved and the result is added to this record. Problem: When the transaction where the webservice is called is not yet finished when the published webservice is called the record with the reference-key is not yet available in the database. Using the java-actions EndTransaction / StartTransaction of community-commons is not an option because i only want to save the record with the reference-key to the database. All other changes have to be roll-backed when the transaction fails. I tried to solve this by backporting the commitInSeparateDatabaseTransaction of a later version of community-commons (which is not available for mendix 5.13.1). Just before calling the webservice the newly created record with the reference-key is saved using commitInSeparateDatabaseTransaction. I tested this by using the debugger and stopped processing after the webservice is called to prevent ending the transaction. But when the published webservice is called the record with the reference-key is not available in the database. Any ideas how this problem can be solved?     SSource of backported CommitIn SeparateDatabaseTransaction for mendix 5.13.1: public class commitInSeparateDatabaseTransaction extends CustomJavaAction<Boolean> {  private IMendixObject mxObject;  public commitInSeparateDatabaseTransaction(IContext context, IMendixObject mxObject)  {   super(context);   this.mxObject = mxObject;  }  @Override  public Boolean executeAction() throws Exception  {   // BEGIN USER CODE   ISession session = getContext().getSession();   IContext newContext = session.createContext();   Core.commit(newContext, mxObject);   newContext.endTransaction();   return true;   // END USER CODE  }  /**   * Returns a string representation of this action   */  @Override  public String toString()  {   return "commitInSeparateDatabaseTransaction";  }  // BEGIN EXTRA CODE  // END EXTRA CODE }      
asked
1 answers
0

What you could do is create a MF which only stores the reference-key on the object.

Call this MF in background just after the WS response.

You should change some Java to make sure the MF is executed immediately and not in a queue or something.

This should make sure the reference-key is stored before the asynchronous response is received.

Also make sure that if the object, on which the reference-key is stored is also changed in the first WS-calling MF, the reference-key is not changed, or it is stored with the same key, so it will not be overwritten in the first called MF.

answered