cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error 500 in CAP entitySet READ

ZMoe
Explorer
0 Kudos
452

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

1.png

 

 

 

 

 

 

 

 

 

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

2.png

 

 

 

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?

Accepted Solutions (0)

Answers (2)

Answers (2)

MioYasutake
SAP Champion
SAP Champion
0 Kudos

@ZMoe 

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

 

ZMoe
Explorer
0 Kudos

@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);
    }
}

 

MioYasutake
SAP Champion
SAP Champion
0 Kudos

@ZMoe 

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?

ZMoe
Explorer
0 Kudos
Yasutake-san, thank you for your reply. Since this exercise is simple demo, so I haven't prepared to use it for updating HANA DB data yet. Is HANADB configuration mandatory for CAP program deployment anyway?(even if I won't use it for data updates?)
MioYasutake
SAP Champion
SAP Champion
0 Kudos
@ZMoe Sorry, I overlooked that your app doesn't use DB. In that case, HANA Cloud is not required. Do you see any detailed errors in the service log (retrieved via cf logs moe-cap-backend-srv)?
ZMoe
Explorer
0 Kudos

@MioYasutake 

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

ZMoe
Explorer
0 Kudos
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: