Having celebrated its 22nd anniversary in 2017, Java has experienced consistent development in its programming efficiency for decades. It is one of the most popular programming languages around the world and is designed to keep running on any stage consistently.
The concept of fundamentally object-oriented architecture, rich set of libraries, platform independence made it favorite to programmers and technology geeks.
Here I am trying to explain, how java can be connect to HANA and expose data as OData which is the Rest based protocol which provides consumption of query able and interoperable RESTful APIs.
What all you need – Basics understanding of java & HANA, eclipse set up(follow any online tutorial)
For Development –
Eclipse IDE (Preferably Neon 3)
JAVA 8 (Java SDK 1.8 / JDK 1.8)
Appropriate MAVEN Version(it provides compact form for deployment, and instead of downloading library files manually, you can easily specify in dependencies of maven, it will automatically downloads when you perform Maven Build.)
JAVA Web Tomcat Server 8 (preferable, better to deploy in HCP)
SAP HANA Cloud platform Account(HCP)
Neo DB tunnel ( for connecting eclipse into HCP)
- Follow the setup of eclipse, use some online resources for that, make sure that MAVEN works perfectly with the above mentioned versions.(follow Eclipse Java set up for HANA).
- Hope you all have understanding of HANA, create table in HANA – store appropriate data , create calculation views on top of HANA tables. ( its possible to expose tables as well as CVs)
Now it comes to the main part –
- Start as a new maven project or download an existing maven project and import it, then edit itJ(it reduces the process of creating a new maven projects)
- Start from your pom.xml – here you specify all your dependencies- it should contain
Apache Olingo is the library for exposing data in form of OData. (OData is an advanced rest protocol ) .when you do the maven Build it automatically downloads all the jar files from the internet.(Make sure that you have active internet connection)
5)Maintain your web.xml
Load-on-startup – This Pre-initialize the servlets, integer field specifies its order of initialization.
- Maintain your persistence.xml
We have to specify the path for our JPA POJO classes here.
Basically we are building a JPA Model here, Java Persistence API provides clear separation between relational databases and models to manipulate it.
‘EMPLOYEE’ is our model here.
- Define the Model EMPLOYEE’
Take care about HANA SQL syntaxes, use Escape character where ever necessary.(\)
- Execution of the named query, by extending ODataJPAServiceFactory class, and Entity manager for connection .
- The data source we have used in Entity manager is DefaultDB, that will be specified in EntityManager class as below –
That has to specify in HCP . will be shown in step 12.
- Open DB tunnel to hana DB using NEO use command
neo open-db-tunnel -a “db_account_id” -h eu1.hana.ondemand.com -u “user id” -p “password” -i jof
its not recommended to hard code credentials, just to connect from local, will be resolved when we deploy.
- Edit server properties
Add the code, Specify the detail from Tunnel
- Update maven project
Project-> righclick ->run as-> maven -> clean install.
Export as war file , or run with SAP Cloud platform server, deploy as follows
Create data source binding
By providing Database credentials, then Start the application access your url for OData
Thanks & Regards,