22 October 2020

#Spring_JPA

#Spring_JPA

Key Concepts


Topic SubTopic Basic Intermediate Advanced Expert
JPA Basics Introduction, Entities, Annotations
Entity Mapping @Entity, @Table, @Id, @GeneratedValue
Relationships @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
JPQL Queries JPQL Basics, Parameters, Named Queries
Spring Data Repositories CrudRepository, JpaRepository, PagingAndSortingRepository
Derived Queries Method Naming, Query Derivation
Paging & Sorting Pageable, Sort, Slice
Custom Queries @Query Annotation, Native Queries
Criteria API CriteriaBuilder, Specifications
Transactions @Transactional, Propagation, Isolation
Caching First Level, Second Level, EhCache, Infinispan
Auditing @CreatedDate, @LastModifiedDate, AuditingEntityListener
Entity Lifecycle @PrePersist, @PostLoad, @PostUpdate
Performance Tuning N+1 Problem, FetchType (LAZY vs EAGER), Batch Fetching
Locking Optimistic Locking, Pessimistic Locking, @Version
Advanced Relationships Composite Keys, @EmbeddedId, @IdClass
JPQL Advanced Joins, Subqueries, Group By, Having
Projections Interface-based, DTO-based, Dynamic Projections
Multi-Database Multiple DataSources, Routing, Schema Separation
Query Optimization Query Hints, Fetch Joins, Plan Caching
Spring Boot Integration Auto Configuration, application.properties, application.yml
Specifications Predicate Composition, Complex Dynamic Queries
Event Handling EntityListeners, Domain Events, Application Events
Hibernate Internals Session, Persistence Context, Dirty Checking
Distributed Transactions XA Transactions, JTA Integration
Advanced Caching Redis, Hazelcast, Custom Cache Providers
Migration Migrating from JDBC/Hibernate to Spring Data JPA
Testing @DataJpaTest, H2 Database, Integration Testing
Best Practices DTO vs Entity, Entity Design, Batch Inserts
Scalability Sharding, Partitioning, Multi-Tenant Databases

Interview question

Basic Level

  1. What is Spring JPA and how does it differ from Hibernate?
  2. What is the role of @Entity annotation?
  3. Difference between CrudRepository, JpaRepository, and PagingAndSortingRepository.
  4. What is the use of @Table annotation?
  5. What is the difference between @Id and @GeneratedValue?
  6. How does JPA support primary key generation strategies?
  7. What is the difference between findById() and getOne()?
  8. Explain the concept of JPA Entity lifecycle.
  9. How does Spring Boot auto-configure JPA?
  10. What are derived queries in Spring Data JPA?
  11. How does query derivation work in Spring JPA?
  12. What is JPQL? How is it different from SQL?
  13. What is the role of @Query annotation?
  14. How do you enable Spring Data JPA in a project?
  15. What is the default fetch type for @OneToMany and @ManyToOne?
  16. Explain the difference between lazy and eager loading.
  17. How do you define relationships between entities?
  18. What is the difference between EntityManager and Session?
  19. How do you configure a datasource in Spring Boot with JPA?
  20. What is @Column annotation used for?
  21. How does pagination work in Spring Data JPA?
  22. Explain the difference between save() and saveAndFlush().
  23. What is the use of Optional in repository methods?
  24. What is an embedded entity in JPA?
  25. What is application.properties role in configuring JPA?

Intermediate Level

  1. How do you implement custom queries in Spring Data JPA?
  2. Difference between nativeQuery = true and JPQL queries.
  3. What is the role of @Modifying annotation?
  4. What are projections in Spring Data JPA?
  5. Difference between interface-based and class-based projections.
  6. How do you use DTO projections in JPA?
  7. What is the purpose of @Transactional in JPA?
  8. Explain transaction propagation types in Spring JPA.
  9. Explain isolation levels in JPA transactions.
  10. What is optimistic locking in JPA?
  11. What is pessimistic locking in JPA?
  12. How does JPA handle entity versioning?
  13. What are entity listeners in JPA?
  14. How do you implement auditing in Spring Data JPA?
  15. What is the purpose of @CreatedDate and @LastModifiedDate?
  16. How do you enable auditing in Spring Boot JPA?
  17. What is the role of @EnableJpaRepositories?
  18. Difference between JPQL and Criteria API.
  19. What is a Specification in Spring Data JPA?
  20. How do you create dynamic queries using Criteria API?
  21. What is the difference between EntityManager.merge() and EntityManager.persist()?
  22. How do you implement batch inserts in JPA?
  23. How does JPA handle relationships in JSON serialization?
  24. What is the N+1 select problem in JPA?
  25. How can you solve the N+1 problem in JPA?

Advanced Level

  1. How do you configure second-level caching in JPA?
  2. Difference between first-level and second-level caching.
  3. Which cache providers can be used with Spring JPA?
  4. How do you integrate Redis/Hazelcast as a cache with JPA?
  5. How does dirty checking work in JPA?
  6. Explain the difference between detach(), clear(), and close() in EntityManager.
  7. What is cascading in JPA? Types of cascade.
  8. What is orphan removal in JPA?
  9. How do you handle composite primary keys in JPA?
  10. Difference between @IdClass and @EmbeddedId.
  11. How do you use fetch joins in JPQL?
  12. How do you tune performance in Spring Data JPA queries?
  13. What are query hints in JPA?
  14. How do you handle multi-tenancy in Spring JPA?
  15. How does JPA support multiple datasources?
  16. What is the difference between JOIN FETCH and normal join?
  17. How do you implement pagination efficiently in large datasets?
  18. Explain the concept of entity graph in JPA.
  19. What is the difference between dynamic and static entity graphs?
  20. How does JPA handle inheritance mapping (SINGLE_TABLE, TABLE_PER_CLASS, JOINED)?
  21. When would you use MappedSuperclass in JPA?
  22. What is the role of @DiscriminatorColumn in inheritance mapping?
  23. How do you use Spring Data JPA with Querydsl?
  24. How do you implement event listeners in JPA (@PrePersist, @PostUpdate)?
  25. Explain lazy loading exceptions and how to avoid them.

Expert Level

  1. How do you design high-performance applications using JPA?
  2. What are the pitfalls of JPA in high-scale systems?
  3. How do you implement distributed transactions in JPA?
  4. Explain JTA and its role with JPA.
  5. What is the difference between XA transactions and local transactions?
  6. How do you use Spring JPA in microservices architecture?
  7. How does Spring JPA integrate with Spring Cloud?
  8. How do you optimize JPA queries for big data systems?
  9. How do you integrate JPA with Kafka for event-driven systems?
  10. How to use JPA with CQRS architecture?
  11. Explain Event Sourcing with JPA.
  12. How to handle schema evolution in Spring JPA applications?
  13. What are advanced strategies for handling large joins in JPA?
  14. How do you ensure zero-downtime deployments with JPA?
  15. What are the best practices for database migrations with JPA (Liquibase/Flyway)?
  16. How do you scale JPA applications with sharding and partitioning?
  17. What is polyglot persistence and how does JPA fit in?
  18. How do you secure JPA repositories in production systems?
  19. What are common anti-patterns in using JPA?
  20. How do you implement domain-driven design with JPA?
  21. How does JPA handle concurrency in distributed environments?
  22. What are advanced caching strategies with JPA?
  23. How do you debug performance bottlenecks in JPA?
  24. How do you profile SQL queries generated by JPA?
  25. How do you combine JPA with reactive programming models?

Related Topics