This guide shows how to connect
SAP HANA Express to a
Spring Boot application using
Hibernate as the JPA provider.
1. Add Dependencies
In
pom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.sap.cloud.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
<version>2.18.14</version>
</dependency>
Make sure
ngdbc.jar
is installed in your Maven local repository.
2. Configure application.properties
spring.datasource.url=jdbc:sap://localhost:39015/?databaseName=HXE
spring.datasource.username=SYSTEM
spring.datasource.password=YourPassword
spring.datasource.driver-class-name=com.sap.db.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.HANARowStoreDialect
This tells Spring Boot to use Hibernate with SAP HANA.
3. Create Entity
import jakarta.persistence.*;
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
// getters and setters
}
4. Repository
import org.springframework.data.jpa.repository.JpaRepository;
public interface CustomerRepository extends JpaRepository<Customer, Long> {
}
5. Test Hibernate Integration
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
CommandLineRunner run(CustomerRepository repo) {
return args -> {
repo.save(new Customer("Alice", "alice@email.com"));
repo.findAll().forEach(c -> System.out.println(c.getName()));
};
}
}
Run with:
mvn spring-boot:run
You should see customer data printed in the console.
image quote pre code