Working with ID on OQL

0
Im trying to pull OQL queries from the system via Java, and I've hit a bit of a brick wall when it comes to IDs over associations. But let me take the problems step by step. First, here is my basic query. Select T1.ID as ID, T1.changedDate as changedDate, T1.RandomString as RandomString, T2.ID as ID_TestTest from MyFirstModule.TestData as T1 left outer join T1/MyFirstModule.TestData_TestTest/MyFirstModule.TestTest as T2   The first issue is that the ID field (which is inherent to each Mendix entity) returns data in a strange format. A row of resultant data (excluding the T2 data) looks like this. [MendixIdentifier:: id=14073748835533001 objectType=MyFirstModule.TestData entityID=50],"1544009321960","TESTESTEST4" Note the non-primitive result for ID. Now, on its own this is not a problem. But If I try to execute the query above, I get the problem: user lacks privilege or object not found: T2.id   My own investigation has revealed this occurs when the association from TestData to TestTest is empty, ie. when no TestTest object is associated with a TestData object. If I replace the T2.ID field with some other attribute on T2, it works as intended, so the issue seems to be because I have a missing non-primitive object T2.ID. So I need one of several solutions: 1) How do I select just the GUID of the mendix object via OQL? 2) How do I handle null ID's on associated objects? 3) How do I pull the association between two objects as part of an OQL statement? If I can solve any of these 3 issues, the problem is solved.
asked
1 answers
2

Hi Hannes,

You could try a CAST like in:

Select 
	T1.ID as ID,
	T1.changedDate as changedDate,
	T1.RandomString as RandomString,
	CAST(T2.ID AS LONG) as ID_TestTest
from MyFirstModule.TestData as T1
left outer join T1/MyFirstModule.TestData_TestTest/MyFirstModule.TestTest as T2

 

The issue is that you cannot (always) select only the plain ID a associated object if you don't do anything else with it. I tried it in 7.19 and a CAST should be enough.

answered