Java Persistence API (JPA) Explained
Fast recall
Quick revision
Core answer
Whether you know JPA is a specification (not a library) and can name the concrete problem it solves versus plain JDBC
Saying 'JPA is Hibernate' or claiming you 'add the JPA library' — JPA is only an interface set; Hibernate/EclipseLink provide the engine
Name the object-relational impedance mismatch and give one concrete example (mapping a User-to-Orders association to a foreign key) instead of just reciting 'it maps objects to tables'
Interview-ready guide
Interview answer
JPA gives Java applications a standard EntityManager API and annotations such as @Entity, @Id, and @ManyToOne. A provider turns those mappings and JPQL queries into database operations. In a Spring Boot Data JPA application, code normally uses Spring Data repositories, Hibernate is the default provider, and Hibernate ultimately uses JDBC. Saying that JPA cannot be downloaded is misleading: the API artifact exists, but it is only the contract and is not enough to persist data without an implementation.
Java Persistence API (JPA) Explained
Direct Answer
Jakarta Persistence, commonly called JPA, is a specification for mapping Java objects to relational data and managing their lifecycle. The API and annotations are published as the jakarta.persistence artifact, while a provider such as Hibernate supplies the implementation. It reduces repetitive mapping code but does not remove the need to understand SQL and transactions.
Code Example
// Spring Boot 3.2 + Java 17 — note jakarta.persistence (not javax)
import jakarta.persistence.*;
import java.util.*;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private String email;
private String name;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Order> orders = new ArrayList<>();
// constructors, getters, setters omitted
}
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email); // Spring derives the SQL
}
@Service
public class UserService {
private final UserRepository userRepository;
UserService(UserRepository r) { this.userRepository = r; }
public User createUser(String email, String name) {
var user = new User();
user.setEmail(email);
user.setName(name);
return userRepository.save(user); // INSERT generated for you
}
}
The annotations are the entire mapping — no SQL string anywhere.
Common Mistakes & Pitfalls
- Thinking JPA is Hibernate — JPA is the contract; Hibernate is one engine that implements it. You can swap Hibernate for EclipseLink without touching entity code.
- Expecting to 'install JPA' — there is no runnable JPA jar; you add a provider (Hibernate via
spring-boot-starter-data-jpa). - Using
javax.persistence— Spring Boot 3.2 moved tojakarta.persistence. Old imports won't compile. - Treating JPA as a SQL replacement — for bulk ETL/reporting, raw JDBC or native queries are still the right tool.
Check your understanding
Answer these without looking back at the article.
- What is the difference between JPA and Hibernate?
- What is the difference between JPA and JDBC?
- What is EntityManager in JPA?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.