The schema id is indeed generated at compile time for built-in widget, and cannot be reused with custom widgets. Personally I thought that either mx.data.get or mx.data.fetch could handle arbitrary depth of associations for custom schema's, but I couldn't find it back in the official documentation.
If your retrieval is always maxed at depth two, you might also retrieve the in-between-entity (Company in your example) as start entity of your query, and apply the xpath constraint you want over the assiociation to the entity you really wanted to retrieve (e.g. CompanyUser/User[original constraint], and add the two references two both user and boss in your schema. You need to post process the result in this work around, but at least you should be able to retrieve everything in one query.
Retrieving data from 2+ level deep can be done in a widget (in pseudo code)
If you want to make it more generic get the entitytype from the meta data api.
I was actually able to find some kind of a work-around but it is very custom and uses some of Mendix's runtime interfaces.
Essentially, I stringified some parameters to send to a MF. The MF calls a Java action which sends a GET request to the server, specifying the schema of the information I want. It's a little more low level than basic XPath and it may or may not be supported.
For anyone who is interested, however, this is some example code:
LocalComponent c = getComponent(); ConnectionBus cb = c.connectionBus(); IXPathTextGetRequest localIXPathTextGetRequest = cb.createXPathTextGetRequest(); IRetrievalSchema schema = cb.createRetrievalSchema(); // Schema creation schema.setMetaObjectName(loan.proxies.Loan.entityName); schema.addMetaPrimitiveName(loan.proxies.Loan.MemberNames.LoanNumber.name()); schema.addSortExpression(loan.proxies.Loan.MemberNames.LoanNumber.name(), SortDirection.ASC); schema.setAmount(5); schema.setAssociationDepth(-1); // Add associative schemas IRetrievalSchema sample = cb.createRetrievalSchema(); sample.setMetaObjectName(loan.proxies.Sample.entityName); sample.addMetaPrimitiveName(loan.proxies.Sample.MemberNames.SampleName.name()); // Add associations to main schema schema.addMetaAssociationSchema( cb.createMetaAssociationSchema(loan.proxies.Loan.MemberNames.Loan_Sample.toString(), sample)); localIXPathTextGetRequest.setQuery("//Loan.Loan"); localIXPathTextGetRequest.setRetrievalSchema(schema); IDataSet localIDataSet = cb.doRequest(this.getContext(), localIXPathTextGetRequest);