Retrieving non persistent object from association with persistent entity in java
I'm trying to retrieve a persistent object from a non persistent object in a java action but I'm failing. The scenario: I've an Object A which is non-persistent. Its associated to persistent object B and Object C. In brief [B<--A-->C] From Object B I can retrieve A, but I can't retrieve C from A. (In my javaaction call within the microflow, I pass object of B, and I expect entity of C. ) Here is the relevant sample code (I pass a ObjectB as a parameter to the JavaAction) this.BParameter1 = __BParameter1 == null ? null : administration.proxies.B.initialize(getContext(), __BParameter1); // BEGIN USER CODE List<IMendixObject> listA= Core.retrieveByPath(getContext(), this.__BParameter1, "A_B"); //association of A and B return listA.size()!=0 ? ((C)listA.get(0).getMetaObject()).getA_C().getMendixObject():null; I expect this to return Object C of the 1st ObjectA in listA. however its failing to work. I can't figure out where I'm going wrong.
To retrieve C by retrieving A from the passed object B and then C from the retrieved non persistent object in the java code can be done by the code below:
// BEGIN USER CODE
List<IMendixObject> listA =Core.retrieveByPath(getContext(), objB.getMendixObject(), "MyFirstModule.A_B");
List<IMendixObject> listC = Core.retrieveByPath(getContext(), listA.get(0), "MyFirstModule.A_C");
// END USER CODE
First a retrieve by path is done following the path from B to A. This will return a list of A objects.
Then using the first object from this list the retrieve by path is triggered to retrieve C by the A_C path. Then the code returns the C object.
In your code you are trying to access the association directly from the metaobject, this is not possible.