I'm enabling an OData v2 proxy, pointing to a Java based OData v4 CAP service. V4 end point is working as expected.
But when requesting v2 (url: http://0.0.0.0:4004/v2/MasterDataService/), I get a 500 Server Error and the following error in console:
Dynamic log level switching not available# [HPM] Proxy created: / -> http://localhost:8080 [HPM] Proxy rewrite rule created: "^/v2" ~> "" app is listing at 0.0.0.0:4004 #2.0#2020 09 07 10:33:35:604#+02:00#ERROR#/cov2ap/Request#####kes9pyrz##########kes9pyrz#PLAIN##CDS compilation failed ../srv/src/main/resources/edmx/csn.json:144: Error: Element "SiteRef_Irn" does not result from the query (in entity:"MasterDataService.Buildings"/element:"SiteRef_Irn")# Sep 07, 2020 10:33:35 AM Logger.js [kes9pyrz] ERROR: CDS compilation failed ../srv/src/main/resources/edmx/csn.json:144: Error: Element "SiteRef_Irn" does not result from the query (in entity:"MasterDataService.Buildings"/element:"SiteRef_Irn") Error: CDS compilation failed ../srv/src/main/resources/edmx/csn.json:144: Error: Element "SiteRef_Irn" does not result from the query (in entity:"MasterDataService.Buildings"/element:"SiteRef_Irn")
For a context, we have an association "SiteRef" which is based on field "SiteRef_Irn", this one being a real field that behaves as a Foreign Key.
I suspect this setup is somehow mistakenly written in CSN file, but I'm not sure what it could be.
Any idea that could help me?
This is how is my proxy script:
const express = require("express"); const proxy = require("@sap/cds-odata-v2-adapter-proxy"); const host = "0.0.0.0"; const port = process.env.PORT || 4004; (async () => { const app = express(); app.use(proxy({ target: "http://localhost:8080", model: "../srv/src/main/resources/edmx/csn.json", services: { "/odata/v4/MasterDataService/": "MasterDataService" } })); const server = app.listen(port, host, () => console.info(`app is listing at ${host}:${port}`)); server.on("error", error => console.error(error.stack)); })();<br>
and this is how csn.json is:
{ "definitions": { "MasterDataService": { "@source": "srv/service.cds", "kind": "service", "@requires": "LocationEditor" }, "MasterDataService.BuildingUsageType": { "kind": "entity", "@cds.autoexposed": true, "query": { "SELECT": { "from": { "ref": [ "sap.cre.core.view.model.Buildings.BuildingUsageType" ] } } }, "elements": { "BuildingRef": { "type": "cds.Association", "target": "MasterDataService.Buildings", "keys": [ { "ref": [ "Irn" ], "$generatedFieldName": "BuildingRef_Irn" } ] }, "UsageType": { "type": "cds.String", "length": 50 }, "StartDate": { "type": "cds.Date" }, "EndDate": { "type": "cds.Date" }, "BuildingRef_Irn": { "type": "cds.String", "length": 50, "@odata.foreignKey4": "BuildingRef" } } }, "MasterDataService.Buildings": { "kind": "entity", "@readonly": true, "@restrict": [ { "grant": "READ", "to": "LocationEditor", "where": "$user.BUILDING = Irn", "_where": "[{\"ref\":[\"$user\",\"BUILDING\"]},\"=\",{\"ref\":[\"Irn\"]}]" } ], "query": { "SELECT": { "from": { "ref": [ "sap.cre.core.view.model.Buildings.Building" ] }, "columns": [ { "ref": [ "Irn" ] }, { "ref": [ "LongName" ] }, { "ref": [ "ShortName" ] }, { "ref": [ "SiteRef" ] }, { "ref": [ "UsageTypes" ] } ] } }, "elements": { "Irn": { "key": true, "type": "cds.String", "length": 50 }, "LongName": { "type": "cds.String", "length": 255 }, "ShortName": { "type": "cds.String", "length": 30 }, "SiteRef": { "type": "cds.Association", "target": "MasterDataService.Sites", "keys": [ { "ref": [ "Irn" ], "$generatedFieldName": "SiteRef_Irn" } ] }, "UsageTypes": { "type": "cds.Composition", "cardinality": { "max": "*" }, "target": "MasterDataService.BuildingUsageType", "on": [ { "ref": [ "UsageTypes", "BuildingRef" ] }, "=", { "ref": [ "$self" ] } ] }, "SiteRef_Irn": { "type": "cds.String", "length": 50, "@odata.foreignKey4": "SiteRef" } }, "$syntax": "projection", "@Capabilities.DeleteRestrictions.Deletable": false, "@Capabilities.InsertRestrictions.Insertable": false, "@Capabilities.UpdateRestrictions.Updatable": false }, "MasterDataService.Sites": { "kind": "entity", "@readonly": true, "query": { "SELECT": { "from": { "ref": [ "sap.cre.core.view.model.Sites.Site" ] }, "columns": [ { "ref": [ "Irn" ] }, { "ref": [ "LongName" ] }, { "ref": [ "ShortName" ] }, { "ref": [ "Intreno" ] }, { "ref": [ "Buildings" ] } ] } }, "elements": { "Irn": { "key": true, "type": "cds.String", "length": 50 }, "LongName": { "type": "cds.String", "length": 255 }, "ShortName": { "type": "cds.String", "length": 30 }, "Intreno": { "@Core.Computed": true, "virtual": true, "type": "cds.String", "length": 40 }, "Buildings": { "type": "cds.Composition", "cardinality": { "max": "*" }, "target": "MasterDataService.Buildings", "on": [ { "ref": [ "Buildings", "SiteRef" ] }, "=", { "ref": [ "$self" ] } ] } }, "$syntax": "projection", "@Capabilities.DeleteRestrictions.Deletable": false, "@Capabilities.InsertRestrictions.Insertable": false, "@Capabilities.UpdateRestrictions.Updatable": false }, "sap.cre.core.view.model.Buildings": { "kind": "context" }, "sap.cre.core.view.model.Buildings.Building": { "kind": "entity", "elements": { "Irn": { "key": true, "type": "cds.String", "length": 50 }, "SiteRef": { "type": "cds.Association", "target": "sap.cre.core.view.model.Sites.Site", "keys": [ { "ref": [ "Irn" ], "$generatedFieldName": "SiteRef_Irn" } ] }, "LongName": { "type": "cds.String", "length": 255 }, "ShortName": { "type": "cds.String", "length": 30 }, "UsageTypes": { "type": "cds.Composition", "cardinality": { "max": "*" }, "target": "sap.cre.core.view.model.Buildings.BuildingUsageType", "on": [ { "ref": [ "UsageTypes", "BuildingRef" ] }, "=", { "ref": [ "$self" ] } ] }, "SiteRef_Irn": { "type": "cds.String", "length": 50, "@odata.foreignKey4": "SiteRef" } } }, "sap.cre.core.view.model.Buildings.BuildingUsageType": { "kind": "entity", "elements": { "BuildingRef": { "type": "cds.Association", "target": "sap.cre.core.view.model.Buildings.Building", "keys": [ { "ref": [ "Irn" ], "$generatedFieldName": "BuildingRef_Irn" } ] }, "UsageType": { "type": "cds.String", "length": 50 }, "StartDate": { "type": "cds.Date" }, "EndDate": { "type": "cds.Date" }, "BuildingRef_Irn": { "type": "cds.String", "length": 50, "@odata.foreignKey4": "BuildingRef" } } }, "sap.cre.core.view.model.Sites": { "kind": "context" }, "sap.cre.core.view.model.Sites.Site": { "kind": "entity", "elements": { "Irn": { "key": true, "type": "cds.String", "length": 50 }, "LongName": { "type": "cds.String", "length": 255 }, "ShortName": { "type": "cds.String", "length": 30 }, "Intreno": { "@Core.Computed": true, "virtual": true, "type": "cds.String", "length": 40 }, "Buildings": { "type": "cds.Composition", "cardinality": { "max": "*" }, "target": "sap.cre.core.view.model.Buildings.Building", "on": [ { "ref": [ "Buildings", "SiteRef" ] }, "=", { "ref": [ "$self" ] } ] } } } }, "$version": "1.0", "meta": { "creator": "CDS Compiler v1.35.0" }, "namespace": "sap.cre.core.view.model" }<br>