a month ago
Hi everyone, I'm new to CAP development. I ran into this problem when building a simple demo in the trial environment.
I have successfully deployed my CAP application to BTP and can access the service metadata.
| https://xxxtrial-dev-moe-cap-backend-srv.cfapps.us10-001.hana.ondemand.com/odata/v4/My_SRV/$metadata |
But when I access the entitySet, I get the following error:
| https://xxxtrial-dev-moe-cap-backend-srv.cfapps.us10-001.hana.ondemand.com/odata/v4/My_SRV/MoeSet |
I generated the CAP framework using the following command:
mvn -B archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds -DarchetypeVersion=RELEASE -DgroupId=com.moe.company -DartifactId=moe-cap-backend -Dpackage=com.moe.company.moecapbackend
Then I created capservice.cds under the srv directory with the following content:
service My_SRV {
@requires: 'any'
entity MoeSet as projection on TestSet;
}
entity TestSet {
key testKey : String(64);
inputData : String(100);
memo: String(100);
outputData: String(100);
}And I also created a MyServiceHandler.java file under the main directory with the following content:
package com.moe.company.mycapbackend;
import java.util.HashMap;
import java.util.Map;
import com.sap.cds.services.cds.CdsReadEventContext;
import com.sap.cds.services.cds.CqnService;
import com.sap.cds.services.handler.EventHandler;
import com.sap.cds.services.handler.annotations.On;
import com.sap.cds.services.handler.annotations.ServiceName;
import com.sap.cds.services.request.UserInfo;
import cds.gen.my_srv.MoeSet;
@ServiceName("My_SRV")
public class MyServiceHandler implements EventHandler {
@On(event = CqnService.EVENT_READ, entity = "My_SRV.MoeSet")
public void beforeReadProducts(CdsReadEventContext context) {
UserInfo userInfo = context.getUserInfo();
MoeSet datamodel = com.sap.cds.Struct.create(MoeSet.class);
datamodel.put(MoeSet.MEMO, userInfo.getName());
Map<Object, Map<String, Object>> result = new HashMap<>();
String key ="test1";
result.put(key, datamodel);
context.setResult(result.values());
}
}Since this is just a simple practice, I didn't add authentication. Here's my mta.yaml file:
_schema-version: 3.3.0
ID: moe-cap-backend
version: 1.0.0-SNAPSHOT
description: "A simple CAP project."
parameters:
enable-parallel-deployments: true
modules:
- name: moe-cap-backend-srv
type: java
path: srv
parameters:
instances: 1
buildpack: sap_java_buildpack_jakarta
properties:
SPRING_PROFILES_ACTIVE: cloud,sandbox
JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jre.SAPMachineJRE']"
JBP_CONFIG_SAP_MACHINE_JRE: '{ version: 17.+ }'
build-parameters:
builder: custom
commands:
- mvn clean package -DskipTests=true --batch-mode
build-result: target/*-exec.jar
provides:
- name: srv-api # required by consumers of CAP services (e.g. approuter)
properties:
srv-url: ${default-url}
Are there any steps I might have missed?
Request clarification before answering.
If you don't use a database, try adding the following profile to the application.yaml.
---
spring:
config:
activate:
on-profile: cloud
cds:
data-source:
auto-config:
enabled: false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@MioYasutake Thank you for your reply.
My application.yaml was automatically generated with the same content as yours. So maybe it shouldn't be the issue here.
I later tried some other methods to fix the error mentioned above. Finally, I resolved it using the approach below (at least that error no longer appears, though I don't understand why). But thank you very much anyway.
I modified the structure/writing style of my .cds file.
Before:
service My_SRV {
entity MoeSet as projection on TestSet;
}
entity TestSet {
key testKey : String(64);
inputData : String(100);
memo: String(100);
outputData: String(100);
}
After:
service My_SRV {
entity TestSet {
key testKey : String(64);
inputData : String(100);
memo: String(100);
outputData: String(100);
}
}
A 500 error when accessing an entity typically occurs when the HANA Cloud is stopped. Can you verify that your HANA Cloud instance is running?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your advice.
I checked the logs.
😢Even though the code doesn't get or update data from the database, according to the log, it seems the CAP backend still tried to connect to some database.
I copied part of the log:
2025-10-16T06:57:39.471+0000 [APP/PROC/WEB/0] STDOUT com.sap.cds.services.impl.ContextualizedServiceException: Error executing the statement (service 'PersistenceService$Default', event 'READ', entity 'My_SRV.MoeSet')
2025-10-16T06:57:39.471+0000 [APP/PROC/WEB/0] STDOUT at com.sap.cds.services.impl.ServiceImpl.dispatch(ServiceImpl.java:269) ~[cds-services-impl-4.4.1.jar:na]
2025-10-16T06:57:39.471+0000 [APP/PROC/WEB/0] STDOUT at com.sap.cds.services.impl.ServiceImpl.emit(ServiceImpl.java:180) ~[cds-services-impl-4.4.1.jar:na]
2025-10-16T06:57:39.471+0000 [APP/PROC/WEB/0] STDOUT at com.sap.cds.services.ServiceDelegator.emit(ServiceDelegator.java:33) ~[cds-services-api-4.4.1.jar:na]
2025-10-16T06:57:39.471+0000 [APP/PROC/WEB/0] STDOUT at com.sap.cds.services.utils.services.AbstractCqnService.run(AbstractCqnService.java:64) ~[cds-services-utils-4.4.1.jar:na]
=======================
2025-10-16T06:57:39.472+0000 [APP/PROC/WEB/0] STDOUT Caused by: com.sap.cds.CdsDataStoreException: SQL: SELECT T0."TESTKEY", T0."INPUTDATA", T0."MEMO", T0."OUTPUTDATA" FROM "MY_SRV_MOESET" T0 ORDER BY T0."TESTKEY" NULLS FIRST LIMIT 1000
2025-10-16T06:57:39.472+0000 [APP/PROC/WEB/0] STDOUT ... 126 common frames omitted
2025-10-16T06:57:39.472+0000 [APP/PROC/WEB/0] STDOUT Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "MY_SRV_MOESET" not found (this database is empty); SQL statement:
2025-10-16T06:57:39.472+0000 [APP/PROC/WEB/0] STDOUT SELECT T0."TESTKEY", T0."INPUTDATA", T0."MEMO", T0."OUTPUTDATA" FROM "MY_SRV_MOESET" T0 ORDER BY T0."TESTKEY" NULLS FIRST LIMIT 1000 [42104-232]And I updated some code today. I added READ and CREATE methods.
But after I deployed it again, I got the same error.
*Even though it's a very simple example, I put the code on Git for now as a reference: https://github.com/moez-1217/moe-cap.git
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.