Skip to Content
Technical Articles

Introducing Hibernate Support for SAP HANA Cloud

What is Hibernate?

Hibernate is a popular object-relational mapping (ORM) framework for Java. The framework can be used to map Java objects from an object-oriented domain model to relational database tables. The framework’s feature set also comprises query and retrieval capabilities which automatically translate between object-oriented Java code and relational SQL queries. Hibernate is an implementation of the Java Persistence API (JPA).

What’s new?

Until now there was no support for SAP HANA Cloud included in the Hibernate framework. Starting with release 5.4.15 there is now a Hibernate dialect for the SAP HANA Cloud column store available. The dialect implements the full range of functions provided by SAP HANA Cloud including database-generated identity columns, sequences, table and column comments, and more.

How can I get started?

To get started you can follow the Hibernate Getting Started tutorial.

In addition to the Hibernate dependencies, you’ll need to add the HANA JDBC driver to your dependency management descriptor (pom.xml if you’re using Maven).

<dependency>
  <groupId>com.sap.cloud.db.jdbc</groupId>
  <artifactId>ngdbc</artifactId>
  <version>2.4.76</version>
</dependency>
Your persistence.xml file should look something like this:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="org.hibernate.tutorial.jpa">
        <description>
            Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide
        </description>

        <class>org.hibernate.tutorial.em.Event</class>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HANACloudColumnStoreDialect" />

            <property name="javax.persistence.jdbc.driver" value="com.sap.db.jdbc.Driver" />

            <!-- Change this to match the connection data for your SAP HANA Cloud database -->
            <property name="javax.persistence.jdbc.url" value="jdbc:sap://<my db>.hanacloud.ondemand.com:443/" />
            <property name="javax.persistence.jdbc.user" value="MY_USER" />
            <property name="javax.persistence.jdbc.password" value="SECRET" />

            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>

    </persistence-unit>
</persistence>

If you don’t have a SAP HANA Cloud instance yet, you can either set up an instance on the SAP Cloud Platform, or you can stay tuned for the free trial that will be available soon.


Happy coding!

Be the first to leave a comment
You must be Logged on to comment or reply to a post.