Hibernate - rahul7838/A-Z-Spring-Resource GitHub Wiki

Question 1: Basic Concepts

What is the difference between Session and SessionFactory in Hibernate? Which one is thread-safe and which one should be created once per application?


Question 2: Entity States

Hibernate entities can be in different states. Can you name the four main entity states and briefly explain what each state means?


Question 3: Mapping

What's the difference between @OneToMany and @ManyToOne annotations? Give a practical example where you'd use each.


Question 4: Lazy Loading

What is lazy loading in Hibernate? What problem does it solve, and what potential issue can it cause?


Question 5: Configuration

In Hibernate configuration, what's the difference between hibernate.hbm2ddl.auto values: create, update, validate, and create-drop?


Question 6: Caching

What are the different levels of caching in Hibernate? Explain the difference between first-level cache and second-level cache.


Question 7: Fetching Strategies

What's the difference between FetchType.LAZY and FetchType.EAGER? When would you use each, and what are the performance implications?


Question 8: HQL vs Criteria API

What is HQL (Hibernate Query Language)? How does it differ from SQL and when would you use HQL vs Criteria API vs native SQL?


Question 9: Cascade Types

Explain the different cascade types in Hibernate (e.g., CascadeType.ALL, CascadeType.PERSIST, CascadeType.REMOVE). Give an example scenario for each.


Question 10: N+1 Problem

What is the N+1 select problem in Hibernate? How can you identify it and what strategies can you use to solve it?


Question 11: Inheritance Mapping

Hibernate supports different inheritance mapping strategies. Can you name the three main strategies and explain when you'd use each?


Question 12: Transaction Management

What's the difference between optimistic locking and pessimistic locking in Hibernate? How do you implement each?


Question 13: Entity Lifecycle

What are Hibernate entity lifecycle callbacks? Name some of the annotations used for lifecycle events.


Question 14: Connection Pooling

Why is connection pooling important in Hibernate applications? Name some popular connection pool implementations used with Hibernate.


Question 15: Advanced Mapping

What's the difference between @JoinColumn and @JoinTable? When would you use each in your mappings?


Pick any question(s) you'd like to answer, or let me know if you want questions on a specific Hibernate topic!