Advantages of JPA over JDBC
Fast recall
Quick revision
Core answer
Understanding of JPA's productivity and maintainability benefits over raw JDBC
Only mentioning less code without explaining features like dirty checking, caching, and lazy loading
Balance the benefits with realistic drawbacks — JPA's magic can cause N+1 queries and unexpected lazy loading issues
Interview-ready guide
Interview answer
For example, a transaction can find Order 42, change its status, and let dirty checking issue the update at flush. A monthly revenue report joining many tables may be clearer as one explicit SQL query mapped to a DTO with JdbcTemplate. The correct choice follows the data shape and workload.
Advantages of JPA over JDBC
Direct Answer
JPA can reduce repetitive row mapping, provide a persistence context with identity and dirty checking, map relationships, support JPQL/criteria queries, and integrate entity operations with transactions. These are productivity and domain-model benefits, not a promise that JPA is faster or superior for every query. JDBC keeps SQL and mapping explicit and is often simpler for bulk, reporting, or database-specific work.
Common Mistakes & Pitfalls
- Ignoring the N+1 query problem: Freshers love lazy loading without realizing it causes one query for the parent and N queries for children, killing performance. They see JPA's magic as pure benefit without understanding hidden database calls.
- Over-relying on automatic dirty checking: Beginners assume every field change auto-saves without understanding transaction boundaries, leading to confusion when changes don't persist outside @Transactional methods.
- Using JPA for everything: Freshers default to JPA even for complex reporting queries with ten-table joins and aggregations, where raw JDBC or native queries would be far clearer and more performant. They don't recognize when JPA's abstraction becomes a liability.
Check your understanding
Answer these without looking back at the article.
- What is Hibernate dirty checking?
- What is the first-level cache in Hibernate?
- When would you prefer JDBC over JPA?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.