Q1. What is JPA?
JPA (Java Persistence API) is a specification for object-relational mapping (ORM) in Java. It provides a standard way to map Java objects to database tables and manage persistence. It defines interfaces and annotations like @Entity, @Id, @OneToMany, etc.
Q2. What is Hibernate?
Hibernate is a popular implementation of JPA. It adds additional features and is often used as the JPA provider. It handles the ORM mapping, caching, and query generation. Spring Data JPA builds on Hibernate (or other JPA providers) to simplify data access.
Q3. What are the advantages of using JPA/Hibernate?
Advantages: reduces boilerplate code, provides object-oriented query language (JPQL), handles relationship mappings, provides caching, automatic schema generation, and database independence. It allows developers to work with objects rather than SQL.
Q4. What is an Entity in JPA?
An entity is a lightweight persistent domain object. It is a plain old Java object (POJO) annotated with @Entity. It has an @Id field to denote the primary key. Entities are mapped to database tables.
Q5. What is the EntityManager?
EntityManager is the JPA interface for interacting with the persistence context. It provides methods for persisting, finding, merging, and removing entities. It also manages transactions and queries. In Spring, you can inject EntityManager via @PersistenceContext.
