Skip to Content
1
May 18, 2020 at 04:49 PM

CAP: Different behavior when deploying to CF and HANA

216 Views Last edit May 18, 2020 at 04:50 PM 2 rev

Hello all,
I would like to share something that's happening to me whilst deploying a CAP (NodeJs) application to Cloud Foundry.
Take this piece of code:

        // * Get the access request:
        const obj = req.data;
        const db  = await cds.connect.to('db');
        const { UserInfo, AccessRequest } = db.entities; <--- THIS LINE FAILS IN CF

        // * Check if there is already an Access Request for this day:
        const accessRequests = await 
             SELECT.from(AccessRequest)
                   .where({ accessDate: moment().format("YYYY-MM-DD") })
                   .and({ initiator_ID: req.user.id })
                   .and({ locationFloor_ID: obj.locationFloor_ID });

This works perfectly when testing locally with sqlite.
Via reflection, variables UserInfo and AccessRequest gets instantiated without a fuss.

When in Cloud Foundry, the reflection doesn't work, so UserInfo and AccessRequest stays "undefined" and the next SELECT fails.

This is the workaround I've found:

        // * Get the access request:
        const obj = req.data;
        const db  = await cds.connect.to('db');
        const { UserInfo, AccessRequest } = db.entities('my.inbox.db'); <-- THIS WORKS

        // * Check if there is already an Access Request for this day:
        const accessRequests = await 
             SELECT.from(AccessRequest)
                   .where({ accessDate: moment().format("YYYY-MM-DD") })
                   .and({ initiator_ID: req.user.id })
                   .and({ locationFloor_ID: obj.locationFloor_ID });

So i simply pass the database model namespace to the entities function.

How is it? Why using sqlite it works without the namespace and in HANA does not?
Shouldn't be the very same, no matter the environment we are working on?

Examples in CAP documentation are very mixed up in cases like these, so I am pretty confused.

Any hint?

Best,
Roberto.