Technical Articles
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 –
- GET <APP-ROOT>/employee/count -> Returns count of total employees in database.
- GET <APP-ROOT>/employee/all -> Returns all employees in database.
- GET <APP-ROOT>/employee/id/{id} -> Returns the employee instance corresponding to the ID.
- 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" }
- 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 –
- Develop the Spring Boot Application (PART 1) – Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 1
- Create instance of HANA service (PART 2) – Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 2
- Deploy and Test (PART 3) – Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 3
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)
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,
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
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
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.
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.
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
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
Nice article. Thanks 🙂
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..
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
Hi Pradeep,
May I know what is the plan that you are using for the HANA HDI Container service ?
i have used hdi-shared plan.
It will not work. I have mentioned this in the blog.
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
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.
With a Spring Boot application like this is it possible to obtain data from On Primese via cloud connector?
Yes
Hi, Boudhayan,
Greate blog!
There should be one step to bind the hana service instance with the Application. If not, how the application know which hdi to bind to ?
If the application want to use a local database through cloud connector, the only option is HANA, right ? The reason is in SCC, only hana can be exposed to BTP .
Best regards!
Jacky Liu