Skip to Content

Cannot create tables using Spring boot in HANA HDI container without CDS artifact

Hi,

I have a basic spring boot application comprising of a Entity (called Topic) and a service that allows CRUD operations on it. I had deployed the application on SAP Cloud Platform - Neo and binded it with the Hana Classic Schema. Hibernate was able to execute DML statements i.e was successful in generating the table in schema.

Now, I tried deploying the same application to Cloud Foundry using HANA hdi containers. The application got deployed but the tables were not created . I checked the logs and it shows me that create operation could not be successful because of insufficient privileges. I do not have any CDS artifact in my project. Is that the reason ? Can we not create database objects via JPA/Hibernate without depending on hdb artifacts for HANA hdi containers ?

Attaching the code and logs below -

1. The logs show the following error -

1. application.properties - springdb is the name of the hana instance and springdatabase is the spring boot application

spring.jpa.hibernate.ddl-auto=update
vcap.services.name=springdb
spring.datasource.driver-class-name=${vcap.services.${vcap.services.name}.credentials.driver}
spring.datasource.url=${vcap.services.${vcap.services.name}.credentials.url}
spring.datasource.username=${vcap.services.${vcap.services.name}.credentials.user}
spring.datasource.password=${vcap.services.${vcap.services.name}.credentials.password}

HANA Service -

2. The main class -

@SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.class})
@ComponentScan("io.javabrains.*")
@EnableJpaRepositories(basePackages = {"io.javabrains.*"})
@EntityScan("io.javabrains.*")
public class SpringDatabaseApplication {
public static void main(String[] args) {
SpringApplication.run(SpringDatabaseApplication.class, args);
}
}

3. The pom. xml -

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.javabrains</groupId>
<artifactId>SpringDatabase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringDatabase</name>
<description>Demo project for Spring Boot JPA</description>
<properties>

<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>

<exclusions>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

 <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-el</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
    <scope>provided</scope>
</dependency>
 <!--  <dependency>
<groupId>com.sap.cloud</groupId>
<artifactId>neo-java-web-api</artifactId>
<version>3.34.3</version>
<scope>provided</scope>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<profiles>
<profile>
    <id>neo</id>
    <properties>
        <activatedProperties>neo</activatedProperties>
    </properties>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
</profile>
<profile>
    <id>cf</id>
    <properties>
        <activatedProperties>cf</activatedProperties>
    </properties>
    <!--  <dependencies>
    <dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies> -->
<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-cloudfoundry-connector</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-spring-service-connector</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.sap.cloud.db.jdbc/ngdbc -->
<dependency>
    <groupId>com.sap.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
<version>1.102.0</version>
</dependency>

    </dependencies>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>
</profiles>
</project>

As you can see from the logs, it says that create operation failed. Why is it so ?

Regards

1.png (6.8 kB)
2.png (109.5 kB)
3.png (107.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Feb 28 at 11:30 AM

    If you are going to use hibernate to generate the DB artifacts then don’t use the HDI HANA service broker. HDI requires all dB artifacts to be design time objects created by the HDI deployer. If you want to use hibernate instead use the normal HANA Schema service broker or even user provided service as you HANA connectivity.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Thomas,

      In SCP CF (Trial account) I could not find an option for the normal HANA schema service. It shows only Hana HDI service. Any other way to use it in CF ?

  • Feb 28 at 01:34 PM

    Then I guess you will have to use the full service to this feature.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 01 at 05:21 AM

    The HANA Schema service broker is not available in cf trial account. So you have to use HDI Service broker. From here on You have two options to execute DDLS in your hana db

    1. If you just want to create the DDLs manually once and try out things, You can do it through Web IDE Database explorer. here is the link to the steps to configure database explorer on web IDE (you may want to skip a lot of stuff in the blog and directly jump to the Database explorer part)

    https://theremotetechie.com/2018/11/09/sap-cloud-foundry-tutorial-connect-a-java-servlet-to-a-hana-hdi-shared-instance-using-an-sap-cloud-foundry-trial-account/

    2. The Second Option, which I believe is the right way to do it, is by defining your data model in cds artifacts and deploy those artifacts using HDI Deploy. here is a link of the HDI deploy documentaion
    https://github.wdf.sap.corp/xs2/hdideploy.js

    Add comment
    10|10000 characters needed characters exceeded