JPA Entities, Lazy Loading and the N+1 Problem
45 min · Advanced
JPA maps Java objects (entities) to database tables so you work with objects instead of SQL rows. Interviewers love three questions here: what the persistence context does, what the N+1 problem is, and why a @Transactional method sometimes does not start a transaction. Section 16 (Spring Data JPA & Hibernate) taught all of it; this lesson is the revision.
Topics in this lesson
- JPA vs Hibernate vs Spring Data JPA
- Entity lifecycle and the persistence context; save vs saveAndFlush
- Lazy vs eager loading; LazyInitializationException
- The N+1 problem and its fixes
- @Transactional: propagation basics and the self-invocation trap
Interview questions this lesson answers
- What is ORM?
- What is the difference between JPA, Hibernate and Spring Data JPA?
- What is an entity, and what does it need?
- What are the ID generation strategies?
- What is the EntityManager?
- What is the persistence context?
- What are the entity lifecycle states?
- What is dirty checking?
- What is the difference between persist and merge?
- What is the difference between save and saveAndFlush?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.