sap-cloud-sdk

SAP Java SDK OData results are sometimes multiplied


I have a small JAVA BTP app that is supposed to read master data from the SAP BP. Most of the time it works very well.

However, I have a small problem with the partner functions. For some reason, the results is multiplied with each call. First I have correctly 6 partner functions, then 12, then 24 etc..

After 1-2 hours I have 6 correct results again.

My call in principle:

private void getBusinessPartnerCustomerSalesAreas() {
    Customer customer = this.businessPartner.getCustomerOrFetch();
    if (customer == null) {
        return;
    }

    this.businessPartnerCustomerSalesArea
            .addAll(customer.getCustomerSalesAreaOrFetch());

    this.getPartnerFunctions();
}

private void getPartnerFunctions() {
    this.businessPartnerCustomerSalesArea.forEach(c -> {
        this.custSalesPartnerFunctions.addAll(c.getPartnerFunctionOrFetch());
    });
}
// ...
    // partner functions output mapping
    if (!this.custSalesPartnerFunctions.isEmpty()) {
        List<CustfactsheetPartnerFunction> partnerFunctions = new ArrayList<>();
        // map partner functions to output format
        this.custSalesPartnerFunctions.forEach(p -> {
            CustfactsheetPartnerFunction partnerFunction = CustfactsheetPartnerFunction.create();
            partnerFunction.setFunction(p.getPartnerFunction());
            partnerFunction.setCustomer(p.getCustomer());
            partnerFunction.setCustomerName(p.getCustomerPartnerDescription());
            partnerFunction.setIsDefault(p.getDefaultPartner());
            partnerFunctions.add(partnerFunction);
        });
        
        returnStruc.setPartnerFunctions(partnerFunctions);
    }

Is there a caching somewhere which I don't see? Other arrays (addresses for example) are not multiplied... I use the newest SDK version. Probably I miss again only a point or so... Thx.


Solution

  • I'm not aware of any implicit caching of OData results.

    Most likely your code maintains multiple copies of similar objects.

    Or in case you use Spring Boot, maybe there is unexpected proxying / caching on your application.