0

I'm using Cloud Application Programming Model for Java developed by SAP, to expose OData services for my colleagues. This is combined with Spring. Service is defined in cds file as follows:

service POAccrualDataController {
entity POAccrualData {
        key OPSYS : String(3);
        EBELN : Integer;
        controller : String(25);
    }
}

As a test, I have made simple controller:

@Controller
@ServiceName("POAccrualDataController")
public class POAccrualDataController2 implements EventHandler {
    @Autowired
    private POAccrualDataService poAccrualDataService;

     @On(event = CdsService.EVENT_CREATE, entity = "POAccrualDataController.POAccrualData")
    public void onCreate(POAccrualData data) {
        POAccrualDataDTO dto = new POAccrualDataDTO();
        dto.setOPSYS(data.getOpsys());
        dto.setEBELN(data.getEbeln());
        dto.setController(data.getController());

        poAccrualDataService.insertPOAccrualData(dto);
}

    @On(event = CdsService.EVENT_READ, entity = "POAccrualDataController.POAccrualData")
    public List<POAccrualData> onRead() {
        List<POAccrualDataDTO> dtoList = poAccrualDataService.getAllPOAccrualData();
        List<POAccrualData> result = new ArrayList<>();
        for(POAccrualDataDTO dto : dtoList) {
            POAccrualData data = POAccrualData.create();
            data.setOpsys(dto.getOPSYS());
            data.setEbeln(dto.getEBELN());
            data.setController(dto.getController());

            result.add(data);
        }

        return result;
    }
}

The defined data transfer object, that is mapped by the database, looks like this:

@Entity
@Table(schema = "databroker")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class POAccrualDataDTO {
    @Id
    @Column
    private String OPSYS;
    @Column
    private Integer EBELN;
    @Column
    private String controller;
}

Controller uses service shown below:

@Service
public class POAccrualDataService {
    @Autowired
    private POAccrualDataRepository poAccrualDataRepository;

    public void insertPOAccrualData(POAccrualDataDTO data) {
        poAccrualDataRepository.save(data);
   }

    public List<POAccrualDataDTO> getAllPOAccrualData() {
        return poAccrualDataRepository.findAll();
    }
}

which is has access to

@Repository
public interface POAccrualDataRepository extends JpaRepository<POAccrualDataDTO, Long> {}

Database is being set up by liquibase. The problem is that, when server starts and I try to access http://localhost:8080/odata/v4/POAccrualDataController/POAccrualData, the GET request is executed succesfully and in the logs I can see following entry from hibernate:

org.hibernate.SQL                        : select poaccruald0_.OPSYS as opsys1_0_, 
poaccruald0_.EBELN as ebeln2_0_, poaccruald0_.controller as controll3_0_ from 
databroker.POAccrualDataDTO poaccruald0_

but when I do the same with POST with the use of Postman, firing request with following body:

{
"OPSYS": "XXX",
"EBELN": 10,
"controller": "controller"
}

produces this output:

org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "POACCRUALDATACONTROLLER_POACCRUALDATA" not 
found; SQL statement: INSERT INTO POAccrualDataController_POAccrualData (EBELN, OPSYS, 
controller) VALUES (?, ?, ?)

When performing save, the table name for some reason changes and therefore I'm not able to persist new objects to the database. I checked in H2 console if everything is working fine, and performing SQL insert this way works. I have also provided custom naming strategy to check if some identifiers are determined wrong and it seems not to be the problem. What I believe is that CAP library provided by SAP defines own Spring beans that overwrite some default behavior - therefore I provided my own JPA configuration to restore some properties. Does anyone has an idea, what can be the source of problems? Link to repository with full project, where you can find pom.xml, liquibase file and my custom configuration: repository.

Mahler
  • 1
  • 3
  • See if this helps - https://stackoverflow.com/questions/32165694/spring-hibernate-5-naming-strategy-configuration – Dhanraj Feb 02 '22 at 10:07

0 Answers0