Hibernate + JPA + Spring-data-jpa + HANA Database

In my previous post we have created a HANA Database(Row) and we have created a Web application to create and see the Users with MySQL

Now lets change the application to work with HANA DB and In SAP HANA Cloud Platform.

1: We need to Access the Database Using JNDI Data Source, Change the Data Source Name as below in the HibernateConfig.java (see the post User App With MySQL)

@Bean
 public DataSource getDataSource() {
 final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
 dsLookup.setResourceRef(true);
 DataSource dataSource = dsLookup.getDataSource("jdbc/DefaultDB");
 return dataSource;
 }

If You are using the HANA Cloud Trail Version we can create only one DataSource that is so the datasource name should be “jdbc/DefaultDB”, other name will not be considered. (Creating the Datasource Name(binding) for the HANA Database we will see in the next step).

2: Change the Hibernate Dialect in the hibProperties() method in the  HibernateConfig.java (see the post User App With MySQL)

Properties properties = new Properties();
 properties.put("hibernate.dialect","org.hibernate.dialect.HANARowStoreDialect");
 properties.put("hibernate.hbm2ddl.auto","create");
 properties.put("hibernate.default_schema","CHIRU");

Dialect is “org.hibernate.dialect.HANARowStoreDialect” Because we have created Row Databse.

hibernate.default_schema should be Database user name which we have created for the Database(refer my previous post ), because the HANA will create the Schema in the USERNAME. I think its only for Trail version.

3: We need to Create the (Data Source Bindings) for the HANA Database.

To do this first we need to deploy the Java application first. follow the post to Deploy the Java web application.

After deploying the application login to the SAP HANA Cloud Platform Cockpit

  1. Click on the “Databases & Schemas”, select the Database which you need to bind for this application
  2. Now we can see the overview screen
  3. Select “Data Source Bindings” from the left navigation panel.
  4. click on “New binding”binding
  5. Data source name Should be , see the Step 1.
  6. select the Java Application
  7. Give the user name which is created in the previous post.
  8. password for the User.

Need to restart the Java Application to take new binding.

Source Code

Advertisements
Hibernate + JPA + Spring-data-jpa + HANA Database

8 thoughts on “Hibernate + JPA + Spring-data-jpa + HANA Database

  1. Hi, thank you for sharing! I have a question how can I use Hibernate as JPA provider when using Apache Olingo for Odata ? could you please tell me how?

  2. chiranjeevigk says:

    @Hamid i have not done that.. i think we can use the DAOs in the OData service implemnetion

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s