08 November 2020

#Hibernate

#Hibernate

Key Concepts


Topic SubTopics Basic Intermediate Advanced Expert
Introduction ORM Concepts, Benefits of Hibernate, JPA vs Hibernate
Configuration hibernate.cfg.xml, Properties, Annotations, Persistence.xml
Session & SessionFactory Session lifecycle, openSession vs getCurrentSession, Thread safety
Mapping Basics Entity mapping, @Entity, @Table, @Id, @GeneratedValue
Relationships One-to-One, One-to-Many, Many-to-One, Many-to-Many
Inheritance Single Table, Joined, Table per Class strategies
HQL & JPQL Queries, Named Queries, Parameters, Pagination
Criteria API Restrictions, Projections, Order, Pagination
Native SQL SQL Queries, Mapping results, Stored Procedures
Caching First-level, Second-level, Query cache, Cache providers (Ehcache, Infinispan)
Transactions Transaction API, ACID properties, Declarative Transactions
Fetching Lazy vs Eager loading, N+1 problem, Fetch Joins
Batch Processing Bulk updates, Batch size, StatelessSession
Performance Tuning Query optimization, Fetch strategies, Cache tuning
Event System Interceptors, EventListeners, Entity lifecycle callbacks
Validation JSR-303 Bean Validation, @Valid, @NotNull
Spring Integration Spring Boot + Hibernate, Transaction Management
Advanced Mappings Composite keys, @EmbeddedId, @MapsId, Join tables
Multi-tenancy Database-level, Schema-level, Discriminator strategies
Hibernate & JPA 2.x+ CriteriaBuilder, Metamodel API, TypedQuery
Concurrency Optimistic vs Pessimistic locking, Versioning
Migration & Versioning Flyway, Liquibase with Hibernate, Schema evolution
Native Integration Hibernate with NoSQL (OGM), Search (Lucene/Elasticsearch)
Testing In-memory DBs (H2), Unit & Integration Testing

Interview question

Basic

  1. What is Hibernate?
  2. Difference between Hibernate and JDBC?
  3. What are the advantages of Hibernate ORM?
  4. What is JPA and how is it related to Hibernate?
  5. Explain ORM in simple terms.
  6. What is the role of hibernate.cfg.xml?
  7. What is the use of SessionFactory?
  8. What is the difference between Session and SessionFactory?
  9. Explain the lifecycle of a Hibernate Session.
  10. What are persistent objects in Hibernate?
  11. What is the difference between transient, persistent, and detached objects?
  12. Explain the role of @Entity annotation.
  13. How do you map a table to a class in Hibernate?
  14. What is @Id and @GeneratedValue annotation used for?
  15. How do you configure database connection in Hibernate?
  16. What is Hibernate Dialect?
  17. Explain HQL (Hibernate Query Language).
  18. What is the difference between HQL and SQL?
  19. How do you perform CRUD operations in Hibernate?
  20. What is the default fetching strategy in Hibernate?
  21. Difference between get() and load() methods?
  22. What are named queries in Hibernate?
  23. Explain the role of @Table annotation.
  24. What is the use of hibernate.properties file?
  25. Explain the difference between save(), persist(), and saveOrUpdate().

Intermediate

  1. What are the different types of entity mapping in Hibernate?
  2. How do you implement one-to-one mapping in Hibernate?
  3. How do you implement one-to-many mapping in Hibernate?
  4. How do you implement many-to-many mapping in Hibernate?
  5. Explain cascading in Hibernate.
  6. What is lazy loading in Hibernate?
  7. Difference between lazy and eager fetching?
  8. What is the N+1 select problem?
  9. How to solve N+1 problem in Hibernate?
  10. What are embedded objects in Hibernate?
  11. Explain inheritance mapping strategies in Hibernate.
  12. Difference between Single Table and Joined strategy?
  13. How do you configure table per class hierarchy?
  14. What is the role of @Inheritance annotation?
  15. Explain the role of @MappedSuperclass.
  16. What are Hibernate annotations used for composite keys?
  17. How do you handle versioning in Hibernate?
  18. Explain optimistic and pessimistic locking.
  19. What is Hibernate Criteria API?
  20. Difference between HQL and Criteria API?
  21. What are projections in Criteria API?
  22. How do you add restrictions in Criteria API?
  23. What is the use of CriteriaBuilder in JPA?
  24. How do you perform pagination in Hibernate?
  25. Difference between Query, TypedQuery, and CriteriaQuery?

Advanced

  1. What is the role of Session.flush()?
  2. What is the difference between flush() and commit()?
  3. Explain clear() and evict() methods.
  4. How do you detach an entity in Hibernate?
  5. What is the use of merge() in Hibernate?
  6. What is the difference between merge() and update()?
  7. What is the first-level cache in Hibernate?
  8. What is the second-level cache in Hibernate?
  9. What cache providers can be used with Hibernate?
  10. What is query-level cache in Hibernate?
  11. How do you configure Ehcache in Hibernate?
  12. Explain Hibernate?s integration with Spring.
  13. What is the role of LocalSessionFactoryBean in Spring?
  14. How do you configure transaction management in Spring + Hibernate?
  15. Difference between programmatic and declarative transactions?
  16. What are Interceptors in Hibernate?
  17. Difference between Interceptor and EventListener?
  18. Explain entity lifecycle events in Hibernate.
  19. How do you use Hibernate with stored procedures?
  20. How do you map native SQL queries in Hibernate?
  21. What are named native queries?
  22. How do you log SQL queries in Hibernate?
  23. Explain batch processing in Hibernate.
  24. How do you configure batch size in Hibernate?
  25. What is StatelessSession in Hibernate?

Expert

  1. What are best practices for Hibernate performance tuning?
  2. How do you optimize Hibernate for large datasets?
  3. How do you use Fetch Joins in Hibernate?
  4. Explain DTO projection using Hibernate.
  5. What is Hibernate Validator and how is it used?
  6. What is JSR-303 Bean Validation in Hibernate?
  7. How do you configure custom validators in Hibernate?
  8. What is a proxy object in Hibernate?
  9. What are bytecode enhancement techniques in Hibernate?
  10. Explain dirty checking in Hibernate.
  11. How does Hibernate detect changes in entities?
  12. What is Hibernate Envers?
  13. How do you implement auditing in Hibernate?
  14. Explain multi-tenancy support in Hibernate.
  15. Difference between schema, database, and discriminator-based multi-tenancy?
  16. How does Hibernate integrate with NoSQL databases?
  17. What is Hibernate OGM?
  18. Explain Hibernate Search and its use cases.
  19. How does Hibernate integrate with Elasticsearch?
  20. Explain polyglot persistence with Hibernate.
  21. How do you handle migration and versioning with Hibernate?
  22. How do you integrate Hibernate with Flyway or Liquibase?
  23. How do you debug Hibernate performance issues?
  24. How does Hibernate differ from JPA, MyBatis, and EclipseLink?
  25. Future of Hibernate: How does it fit into modern microservices and cloud-native architectures?

Related Topics