This guide explains best practices for data modeling when using SAP HANA Express with Spring Boot. The focus is on clean design and easy integration.
1. Use Proper Naming Conventions
- Use singular table names (User, Order, not Users, Orders).
- Use lowercase with underscores for columns (first_name, created_at).
- Keep consistency across HANA tables and Java entities.
2. Define Primary Keys Clearly
Always define a primary key:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
In SAP HANA, use integer or bigint as ID for performance.
3. Normalize Where Needed, Denormalize Where Useful
- Normalization: avoid redundant data for core models (like User, Product).
- Denormalization: for reporting tables or analytics, store computed values.
4. Use Proper Data Types
- Map HANA NVARCHAR to Java String.
- Map HANA DECIMAL to Java BigDecimal.
- Avoid oversized columns — size impacts memory in HANA.
5. Leverage JPA Relationships
Use JPA mappings to model relations:
@OneToMany(mappedBy = "user")
private List<Order> orders;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
Keep relationships simple and avoid deeply nested mappings.
6. Add Indexes for Performance
In SAP HANA, create indexes for frequently queried fields:
CREATE INDEX IDX_USER_EMAIL ON USERS(EMAIL);
Also use @Column(unique = true) in entities when applicable.
7. Use DTOs for API Responses
Don’t expose entities directly. Use DTOs to send responses:
public record UserDTO(String name, String email) {}
Map entity to DTO in service layer.
8. Test with Sample Data
Seed data at startup to validate your model:
@Bean
CommandLineRunner init(UserRepository repo) {
return args -> {
repo.save(new User("Alice", "alice@email.com"));
repo.save(new User("Bob", "bob@email.com"));
};
}
image quote pre code