Java 自定义VDM对象上缺少getter方法
我在S/4Hana云中创建了一个自定义业务对象 自定义对象 然后获取元数据,最后添加到我的java项目中。Java 自定义VDM对象上缺少getter方法,java,sap-cloud-sdk,Java,Sap Cloud Sdk,我在S/4Hana云中创建了一个自定义业务对象 自定义对象 然后获取元数据,最后添加到我的java项目中。 现在,我需要阅读该表,并使用一些字段进行后续逻辑 我通过以下方式检索表: cockpitSetupList = new DefaultCscCockpitSetupService().getAllCSCCOCKPIT_SETUP() .orderBy(CSCCOCKPIT_SETUP.COCKPIT_TYPE, Order.ASC)
现在,我需要阅读该表,并使用一些字段进行后续逻辑 我通过以下方式检索表:
cockpitSetupList = new DefaultCscCockpitSetupService().getAllCSCCOCKPIT_SETUP()
.orderBy(CSCCOCKPIT_SETUP.COCKPIT_TYPE, Order.ASC)
.execute();
我想读取字段值,所以我循环读取字段值,如下所示:
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);
但是,它没有给出字段的值,而是类似于:
"com.sunstar.vdm.namespaces.csccockpitsetup.field.CSCCOCKPIT_SETUPField@d6ba2449"
例如,通过使用白名单API,我为API的每个字段都提供了getter
你们能告诉我为什么在自定义VDM对象上看不到getter方法吗
备注:我已经创建了两个额外的自定义对象,但没有一个会带来getter
正在添加元数据文件:[已删除到字符限制]
正在添加我的POM文件:
<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>
com.sap.cloud.s4hana.cloudplatform
比尔,
Pietro我假设您使用生成器根据元数据生成VDM。如果有,如果可能,请共享元数据
假设存在上述情况,您尝试使用的字段不会也不打算保存任何数据。它将在构建OData请求时使用,因此在选择和筛选操作中也是如此
为了访问数据,您确实需要实体类型的getter。确保在项目中包含lombok
作为依赖项,因为我们在生成的代码中使用@Data
:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
如果您在IDE中看不到这些方法,您可能需要安装或启用一个,以便linter&autocomplete正常工作。您好,MatKuhr,我刚才在问题中添加了元数据。谢谢。我已经把它放在我的POM里了。事实上,我有两次,所以我只留了一次。即便如此,我还是看不到有人能做到。我附上了POM文件和创建的方法的图片。我有两个get方法,但不适用于我需要的字段,即salessorganization和Plant。我仔细研究了一下,使用了3个自定义对象和3个自定义CDS视图。它们都有setter方法,但没有getter方法。我成功地仅在白名单API中使用了getter。我扩展了我的答案。您能否确认在实体类中看到私有字段,例如,private String salessorganization代码>和类级别上的@Data
注释?如果没有,请扩展您的问题,以包括调用生成器的确切方式。您完全正确。问题是缺少Lombok插件。通过添加so,我可以看到实体的私有字段(例如getSalesOrganization)。多谢各位。这对我帮助很大。
final CSCCOCKPIT_SETUP setup = new CSCCOCKPIT_SETUP();
final String salesOrganization = setup.getSalesOrganization();