Skip to Content
Technical Articles
Author's profile photo Boudhayan Dev

Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 3

We will continue from where we left off in the previous part  where we finished configuring the HANA Database and the user that will communicate with the database.

STEP 4: Deploy the Application

Let’s build the war file first. If you are using Eclipse, then perform a maven build and specify profile as cf.  Otherwise, you can also build the application using maven command line tool with the following command –

mvn clean install -P cf

Let’s push the application to cloud foundry space now.To deploy the application, execute the following command from project root –

cf push

If everything goes alright, you should have your application deployed in Cloud Foundry. You can check the status of the application using –

cf app spring-hana-cloud-foundry

 

Yay ! The application is deployed. You can try out the endpoints as follows –

  1. GET <APP-ROOT>/employee/count -> Returns count of total employees in database.
  2. GET <APP-ROOT>/employee/all -> Returns all employees in database.
  3. GET <APP-ROOT>/employee/id/{id} -> Returns the employee instance corresponding to the ID.
  4. POST <APP-ROOT>/employee/add -> Add a new employee in database. Use the following payload in body –
    {
    	"id":"1",
    	"firstName":"Boudhayan",
    	"lastName":"Dev",
    	"email":"email@example.com",
    	"contact":"12121212"
    }
  5. DELETE <APP-ROOT>/employee/delete/{id} -> Delete particular employee from database.

 

STEP 5: Check Database content.

Execute few POST requests as listed above to insert some items in the database. We will now check the database with the Database user to see those records –

Launch SAP HANA Cockpit with the Database user –

If you are still logged on with the SYSTEM user, try logging out by clicking Clear Credentials. This would prompt you to enter credentials. Use the credentials found in the service key that we created earlier in step 3.

Once logged in, click Open SQL Console. This will open the database explorer where you can check the database artifacts created by this user –

As you can see, the table – EMPLOYEE exists for the database user. If you open the contents of this data, you’ll find the records that were inserted.

 

I have inserted 3 records earlier, which can be seen in the database above. We have successfully, bound HANA DB to our application in SAP Cloud Platform (CF).

This completes the 3 part blog series where we saw how to create a Spring Boot Application and bind it t HANA database. In case of any doubts or queries, do leave out your message. I’ll be happy to help.

All the best !

Thanks

 

Find the remaining parts here –

  1. Develop the Spring Boot Application (PART 1) – Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 1
  2. Create instance of HANA service (PART 2) – Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 2
  3. Deploy and Test (PART 3) – Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 3

Assigned Tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Chaithanya Mirle Kantharaju
      Chaithanya Mirle Kantharaju

      Hello Boudhayan Dev,

       

      This is a fantastic blog! Thanks for this.

      However, I tried the exact same project using your own code. I have deployed on my trial account of cloud foundry using HDI-Shared plan.

      And when I run any service, I'm getting the below error (Example of /employee/count)

      "could not prepare statement; SQL [select count(*) as col_0_0_ from employee employee0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement",

      It looks like the hibernate dialect for HANA is having trouble generating SQL. Please help in resolving this.

      BTW, I used a new version of HANA driver dependency (not the one you have mentioned in the blog)

       

      Thanks,

       

       

      Author's profile photo Boudhayan Dev
      Boudhayan Dev
      Blog Post Author

      Hello Chaithanya Mirle Kantharaju ,

       

      You need to use the schema plan of the HDI Service.

      The error is because hibernate could not create a connection with the database in the first place. Schema plan is not available in Trial landscape as far as i know.

      Regards,

      Boudhayan Dev

      Author's profile photo Chaithanya Mirle Kantharaju
      Chaithanya Mirle Kantharaju

      Hello,

      Ah ok. So there is no way to deploy a Spring JPA with this dialect on trial account then?

      Can you explain why do you need a schema plan only? even HDI shared also internally creates a schema for my user but on a shared db isn't it?

       

      Thanks,

      Chaithanya

      Author's profile photo Boudhayan Dev
      Boudhayan Dev
      Blog Post Author

      Well Yes, HDI shared creates a schema as well but from what I gathered during my research with this topic is that hdi-shared creates a container for deploying CDS artifacts. As such, it  is to be used for CDS based database modelling projects.

      And schema plan for direct binding to applications - similar to PostGres, MySQL schemas. Ill try linking the article if I find it. Meanwhile, you can try the live/canary acc if you have access to.

      Author's profile photo Chaithanya Mirle Kantharaju
      Chaithanya Mirle Kantharaju

      Finally got it working. I created a table with same name directly on DB using WebIDE - Database explorer and services are working just fine.

      Thanks for your support. Looking forward to more blogs based on Spring and Spring cloud.

       

      Author's profile photo Boudhayan Dev
      Boudhayan Dev
      Blog Post Author

      Chaithanya Mirle Kantharaju 

      Oh that’s good to hear. Great.

       

      However, this would be cumbersome to maintain and update when the number of tables increase. Then you will have to fall back to the schema plan. Also, I found the question which I had asked few months earlier regarding the usage of HDI – hdi-shared and schema plan –

       

      https://answers.sap.com/questions/772741/cannot-create-tables-using-spring-boot-in-hana-hdi.html

       

      This might be helpful.

       

      Regards

      Author's profile photo Pradeep V
      Pradeep V

      Hi ,

      I am trying to achieve the same and did you do it in HDI-shared plan ?

      if yes please let me know the steps.

       

      Thanks in advance

      Pradeep

      Author's profile photo Mihir Chittora
      Mihir Chittora

      Nice article. Thanks 🙂

      Author's profile photo Pradeep V
      Pradeep V

      Hi,

      Great Blog, I was following your blog and i followed exactly whatever you have mentioned in the Cloud foundry Spring boot app with the hibernate , when i push my code the CF i am getting the following error in the app logs

       

      i am using the hana trial account..

       

      Caused by: com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [258]: insufficient privilege: Detailed info for this error can be found with guid ’21FDA09352F3474A8E9760CF6C4034BA’

      even i tried granting the select insert update delete permission on the table from sap web ide  data base explorer but still it is throwing the same error, Please help

       

      Any help would be great.

       

      thanks

      Pradeep

       

      Author's profile photo Boudhayan Dev
      Boudhayan Dev
      Blog Post Author

      Hi Pradeep,

       

      May I know what is the plan that you are using for the HANA HDI Container service ?

      Author's profile photo Pradeep V
      Pradeep V

      i have used hdi-shared plan.

      Author's profile photo Boudhayan Dev
      Boudhayan Dev
      Blog Post Author

      It will not work. I have mentioned this in the blog.

      Now that we have provisioned a HANA DB for us, it is time to create an instance of HANA Schema and HDI Service. This service generates a schema (if you use schema plan) which allows your Spring Boot application to create its database artifacts. There are other plans ofcourse which cater to different use-cases. For example, if you follow the Cloud Application Programming model, it is recommended to model the database artifacts in CDS. In that case, hdi-shared plan is used, which deploys the database artifacts from your CDS files.

      However, in this exercise we will make use of the schema plan, as our database tables are defined in the application layer itself.

      Author's profile photo Pradeep V
      Pradeep V

      But in the comments i can see it worked for Chaithanya Mirle Kantharaju by creating table manually.

      So i tried by that as well, and it still throws the same error.

       

      Anyways thank you so much for the valuable reply, i will try using the schema plan and check .

       

      Thank you,

      Pradeep

      Author's profile photo Chaithanya Mirle Kantharaju
      Chaithanya Mirle Kantharaju

      Apologies for the delay. I saw your response now 🙁

      Well I wasn't getting this error.

      I created the tables manually using the WebIDE and it worked fine. Maybe you could try that.

       

      Author's profile photo Rafael Valim
      Rafael Valim

      With a Spring Boot application like this is it possible to obtain data from On Primese via cloud connector?

      Author's profile photo Boudhayan Dev
      Boudhayan Dev
      Blog Post Author

      Yes