Object Relational Mapping (ORM) is a technique that lets you use Java objects to interact with a relational database (like PostgreSQL) — without writing raw SQL.
Think of it like this:
Java (Object World) | PostgreSQL (Relational World) |
---|---|
User class |
users table |
user.getName() |
SELECT name FROM users |
userRepository.save(user) |
INSERT INTO users (...) |
ORM maps between:
Why ORM is useful:
In Spring Boot:
We use JPA (Java Persistence API) as the standard, and Hibernate as the default ORM tool.
You write Java classes like this:
java
@Entity
public class User {
@Id
private Long id;
private String name;
}