I created a custom business object in S/4Hana Cloud.
custom object
Then get the metadata, and finally add to my java project.
Now I need to read the table and use some of the fields for subsequent logics.
I retrieve table this way:
cockpitSetupList = new DefaultCscCockpitSetupService().getAllCSCCOCKPIT_SETUP()
.orderBy(CSCCOCKPIT_SETUP.COCKPIT_TYPE, Order.ASC)
.execute();
I would like to read the value of the fields, so I loop it and read the field value like this:
for (CSCCOCKPIT_SETUP cockpitsetup : allCockpitSetup) {
// read all the product for the sales Organization sent from cockpit setup
String salesOrganizationInString =
String.valueOf(cockpitsetup.SALES_ORGANIZATION);
allProductsPerSalesOrganization = products.getAllProductSalesPerSalesOrganization(salesOrganizationInString);
But, it does not give the value of the field, but something like:
"com.sunstar.vdm.namespaces.csccockpitsetup.field.CSCCOCKPIT_SETUPField@d6ba2449"
By using whitelisted APIs, for instance, I have getters for each field of the API.
Could you guys tell me why I do not see getter methods on custom VDM objects?
Remarks: I´ve created two additional custom object and none of them brings getters.
Adding the metadata file: [removed to character limit] Adding my POM file:
<dependencies>
<dependency>
<groupId>com.sap.cloud.s4hana.cloudplatform</groupId>
<artifactId>scp-neo</artifactId>
</dependency>
<dependency>
<groupId>com.sap.cloud.s4hana</groupId>
<artifactId>s4hana-all</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sap.cloud</groupId>
<artifactId>neo-javaee7-wp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<!-- commented out to get VDM getters -->
<!-- <dependency>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>1.1.2</version>
</dependency>
<!-- custom VDM-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- custom VDM -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Also, a list of the methods generated: methods BR, Pietro
I assume you used the generator to generate the VDM based on the metadata. If so and if possible, please share the metadata.
Assuming the above, the field that you are trying to use does not and is not meant to hold any data. It is to be used when building OData requests, so in select and filter operations.
In order to access the data you would indeed need getters on the entity type. Be sure to include lombok
as dependency in your project as we use the @Data
annotation in the generated code:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
I generated the code locally and I see that the annotation is present on the entity. So there should be getters present. I setup a small project and the following code compiles:
final CSCCOCKPIT_SETUP setup = new CSCCOCKPIT_SETUP();
final String salesOrganization = setup.getSalesOrganization();
If you don't see the methods in your IDE you might need to install or enable a lombok plugin for the linter & autocomplete to work properly.
Hi MatKuhr, I just added the metadata in the question. Thanks.
I had it in my POM already. Actually, I have it twice, so I kept one only. Even so, I still cannot see getters. I attached the POM file and a picture of the methods created. I do have two get methods, but not for the fields I need, which are salesOrganization and Plant.
I look into it a bit, and I am using 3 custom objects and 3 Custom CDS views. All of them have setters methods, but no getter methods. I managed to use getter successfully with whitelisted APIs only.
I expanded my answer. Can you confirm that you see the private fields in the entity class, e.g.
private String salesOrganization;
and the@Data
annotation on the class level? If not, please expand your question to include the exact way you invoke the generator.You were dead on target. The issue was the missing Lombok plugin. By adding so, I can see the private fields of the entity (e.g., getSalesOrganization). Thank you a lot. It helped me very very much.