java and non persistent object relations

I have a java action that creates a non-persistent object A. Then creates several objects B (also non-persistent) and sets the association for B to A within the context of B. So like this (not the complete code): // BEGIN USER CODE IContext context = Core.createSystemContext(); A new_A= createA(context); // END USER CODE // BEGIN EXTRA CODE private A createA(IContext context){ A object_A = new A(context); B object_B = new B(object_A.getContext()); objectB.setB_A(object_A.getContext(),A); return A; } //END EXTRA CODE In the user code section I call a function that runs a microflow which I pass the object A to be used as parameter. When this microflow runs the first step is to retrieve the associated objects B. In Mendix version 4.x this action will retrieve the associated objects, in Mendix version 5.3.2 the associated objects are not retrieved. It seems they are not available in the context of the microflow. I have tried the Core.execute with the context I pass to the function (so the context from the user section), also with the context of the A object (checked that his is not null), but in both cases the microflow is not aware of the associated objects. Also tried to create the associated objects with the passed context, then the associations are not available in the java code. When using the context from createtime of A the associated objects are available in the java code that runs the microflow. Checked by executing a Core.retrieveByPath and checking the returned list. This list contains the associated objects. Furthermore tried to run the microflow with the passed context from the USER CODE section and with the context of createtime of A, but this also will not get the associated objects in the microflow. My question is, as this worked in version 4 and doesn't in version 5, if this a bug or does this need to be implemented differently.
1 answers

You are creating a new context in your Java action. That means the non-persistent objects you are creating will only be retained in that context. Your microflow is probably running in some user context, from which the objects are not guaranteed to be reachable. In fact, in this case they will have probably been removed from the object memory when the action ended. (note: this explanation is simplified a bit)

I think you have two options to implement this:

  1. Use the context of the microflow, so "this.getContext()" in the user section. NOT the context you just created. This should work, but if it doesn't, please attach your full java action code for this case.
  2. If you need to use multiple contexts, you can use the ISession.retain() method ("this.getContext().getSession().retain(IMendixObject)") to make sure the object is kept in memory. Be careful, because this will make you responsible for cleaning up the object when you are done!

See this page for more information about this behaviour: