This guide shows how to
optimize performance when using
SAP HANA Express with
Spring Boot. Follow these best practices directly.
1. Use Connection Pooling
Enable connection pooling with HikariCP (default in Spring Boot):
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.max-lifetime=1800000
This reduces overhead from creating new DB connections.
2. Optimize Queries with Indexes
Add indexes to frequently queried columns in SAP HANA:
CREATE INDEX IDX_PRODUCT_NAME ON PRODUCT(NAME);
Combine with JPA queries for faster lookups.
3. Use Pagination for Large Datasets
Instead of fetching all rows:
Page<Product> products = repo.findAll(PageRequest.of(0, 20));
Always retrieve data in
chunks to improve speed.
4. Apply Caching
Enable Spring Cache to avoid repeated DB hits:
@Cacheable("products")
public Product getProduct(Long id) {
return repo.findById(id).orElseThrow();
}
5. Reduce N+1 Queries
Use
@EntityGraph
or
fetch = FetchType.LAZY
for relationships:
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private List<Order> orders;
This prevents unnecessary queries.
6. Batch Inserts and Updates
Group multiple operations into one transaction:
@Transactional
public void saveAll(List<Product> products) {
repo.saveAll(products);
}
This reduces commits and speeds up inserts.
7. Monitor with Actuator
Enable Spring Boot Actuator for metrics:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Check DB health and performance endpoints.
image quote pre code