Basic Concepts
- What is JPA, and how does it differ from JDBC?
- Explain the role of the Entity Manager in JPA.
- What are the different types of persistence contexts in JPA?
- Describe the lifecycle of an entity in JPA.
- What is the purpose of the
@Entity
annotation? - How do you configure the JPA persistence unit in a Spring Boot application?
- What are the different fetching strategies available in JPA?
- Explain the difference between
@Table
and@Entity
annotations.
Mapping and Annotations
- How do you map a one-to-one relationship in JPA?
- Explain the use of
@JoinColumn
in a many-to-one relationship. - What is the purpose of the
@ManyToMany
annotation, and how is it implemented? - How do you configure a bidirectional relationship in JPA?
- Describe how to use
@OneToMany
and@ManyToOne
annotations together. - What is the
@MappedSuperclass
annotation used for? - How does the
@Embeddable
annotation work, and what is its use case? - Explain how to use
@ElementCollection
for storing a collection of basic types.
Querying
- What are JPQL and the differences between JPQL and SQL?
- How do you create a custom JPQL query?
- Explain the use of the
@Query
annotation in Spring Data JPA. - How do you use the Criteria API for dynamic queries in JPA?
- Describe the
EntityManager
methods for querying entities. - How can you execute native SQL queries using JPA?
- What is the purpose of
@NamedQuery
and how is it used? - How do you handle pagination and sorting with JPA?
Transactions and Concurrency
- How does JPA handle transactions, and what are the different transaction types?
- Explain the
@Transactional
annotation and its role in transaction management. - What are the different isolation levels available in JPA transactions?
- Describe optimistic locking and how it is implemented in JPA.
- How do you handle pessimistic locking in JPA?
- What are the implications of using
@Version
for optimistic locking? - How can you configure transaction timeout in JPA?
- Explain how JPA manages entity state transitions in a transaction.
Performance and Optimization
- How do you optimize JPA performance for large datasets?
- What is the purpose of the
@Cacheable
annotation, and how does it work? - How do you use query hints to improve JPA query performance?
- Explain how you can use batch processing with JPA.
- What are the differences between eager and lazy loading, and how do you manage them?
- How do you handle N+1 select problems in JPA?
- Describe how the
@Fetch
annotation can be used to control fetching strategies. - What are the advantages and disadvantages of using
@BatchSize
in JPA?
Advanced Topics
- What are the differences between
@EntityGraph
andJOIN FETCH
in JPA? - How do you implement soft deletes using JPA?
- Explain the concept of multi-tenancy in JPA and how to configure it.
- How do you use JPA with a non-relational database?
- What are some common pitfalls when using JPA with complex object graphs?
- Describe the use of
@PostLoad
,@PostPersist
,@PostUpdate
, and@PostRemove
lifecycle callbacks. - How do you implement custom converters with JPA?
- What is the role of the
@Access
annotation in JPA?
Error Handling and Troubleshooting
- How do you handle and log exceptions in JPA?
- What are common causes of
LazyInitializationException
, and how do you resolve them? - Describe how to diagnose and troubleshoot performance issues in JPA applications.
- How do you handle entity not found exceptions in JPA?
- What are some common JPA mapping errors and how can you avoid them?
- How do you debug issues related to entity state transitions in JPA?
- Explain how to address issues with entity identity and primary keys.
- How do you deal with constraints and database schema mismatches in JPA?
Integration with Spring Boot
- How do you configure JPA repositories in Spring Boot?
- Explain how Spring Data JPA simplifies repository implementations.
- What is the role of
EntityManagerFactory
andTransactionManager
in Spring Boot with JPA? - How do you use Spring Boot’s automatic configuration for JPA?
- Describe how you can define custom queries in a Spring Data JPA repository.
- What is the purpose of
@Repository
annotation in Spring Data JPA? - How do you handle exception translation in Spring Data JPA?
- What is the role of
@EnableJpaRepositories
in Spring Boot?
Schema Management
- How does JPA handle schema generation and DDL operations?
- Describe the use of
@Table
annotation and its attributes. - How do you customize table and column names using JPA annotations?
- What is the role of
schema-generation
settings in JPA? - How do you use the
@SecondaryTable
annotation for multi-table mapping? - Explain the use of
@AssociationOverride
and@AttributeOverride
annotations. - How do you manage schema evolution and database migrations with JPA?
- What are the best practices for schema management in a production environment?
Miscellaneous
- How do you handle large text fields or blobs in JPA?
- What is the difference between
@GeneratedValue
strategies in JPA? - How do you map and use enums in JPA?
- Explain the use of
@Transient
and@PostConstruct
annotations in JPA. - How do you implement and use inheritance with JPA?
- What are the advantages of using JPA over plain JDBC for data access?
- How do you perform database migrations with JPA?
- Describe how you would use JPA with Spring Boot’s integration testing support.
Best Practices and Patterns
- What are some best practices for using JPA in high-performance applications?
- How do you handle database connections and resource management with JPA?
- What patterns and practices should be followed when using JPA with complex domain models?
- How can you ensure data consistency and integrity when using JPA?
- What are some common design patterns for optimizing JPA applications?
- How do you handle concurrency control and conflicts in JPA?
- What are some strategies for caching entities in JPA?
- How do you use DTOs (Data Transfer Objects) with JPA?
Migration and Evolution
- How do you handle schema migrations with JPA in a continuous integration/continuous deployment (CI/CD) pipeline?
- Explain the use of tools like Liquibase or Flyway for schema management with JPA.
- How do you manage and handle legacy database schemas with JPA?
- What are some strategies for evolving JPA-based applications over time?
- How do you migrate from one JPA implementation to another?
- What are the considerations for upgrading JPA versions in an existing application?
- How do you handle changes in database schemas when using JPA?
- What are the implications of changing entity mappings in a production environment?
Real-World Scenarios
- How would you approach refactoring an existing JPA application to improve performance?
- Describe a scenario where you had to debug a complex JPA issue and how you resolved it.
- How do you handle multi-tenant data access in a JPA application?
- Describe a complex data migration project involving JPA and how you managed it.