Question 1: What is the main role of Hibernate in Java applications?
- UI rendering
- Transaction management only
- Object Relational Mapping
- JVM optimization
Explanation: Hibernate maps Java objects to relational database tables.
This intermediate Hibernate quiz is designed for developers who know Hibernate basics and want to strengthen real-world ORM usage. It focuses on entity states, fetching strategies, caching, relationships, HQL, performance tuning, and commonly asked Hibernate interview questions.
Explanation: Hibernate maps Java objects to relational database tables.
Explanation: SessionFactory creates and manages Session instances.
Explanation: Session is not thread-safe and should not be shared.
Explanation: Session represents a unit of work.
Explanation: Persistent objects are associated with a Session.
Explanation: Transient objects are not associated with Session.
Explanation: Detached objects were once persistent.
Explanation: save() makes a transient object persistent.
Explanation: update() reattaches a detached entity.
Explanation: merge() returns a managed instance and copies state.
Explanation: Lazy fetching loads data on demand.
Explanation: Eager fetching loads associations immediately.
Explanation: @Fetch controls Hibernate fetching behavior.
Explanation: @ManyToOne is EAGER by default.
Explanation: @OneToMany is LAZY by default.
Explanation: N+1 occurs when extra queries are triggered for associations.
Explanation: Fetch join retrieves associations in one query.
Explanation: First-level cache is enabled by default.
Explanation: Session provides first-level caching.
Explanation: Second-level cache is shared across sessions.
Explanation: Query cache stores HQL query results.
Explanation: flush() syncs session changes with DB.
Explanation: clear() removes all entities from Session.
Explanation: evict() removes a single entity from cache.
Explanation: HQL is database-independent.
Explanation: FROM Entity retrieves all records.
Explanation: Native Query allows raw SQL usage.
Explanation: CascadeType defines cascading rules.
Explanation: ALL propagates all operations.
Explanation: REMOVE deletes associated entities.
Explanation: @Inheritance defines inheritance strategy.
Explanation: TABLE_PER_CLASS uses separate tables.
Explanation: SINGLE_TABLE uses discriminator column.
Explanation: Caching significantly improves performance.
Explanation: @Version enables optimistic locking.
Explanation: Hibernate throws OptimisticLockException.
Explanation: Optimistic locking prevents lost updates.
Explanation: Batch size enables batching.
Explanation: @BatchSize enables batch fetching.
Explanation: Dialect handles database-specific SQL.
Explanation: Dialect abstracts DB differences.
Explanation: Criteria API builds queries programmatically.
Explanation: JPA Criteria is type-safe.
Explanation: Transaction manages commit and rollback.
Explanation: commit() persists transaction changes.
Explanation: ORM removes SQL boilerplate.
Explanation: Hibernate simplifies object-oriented persistence.
This intermediate Hibernate quiz is designed for developers who know Hibernate basics and want to strengthen real-world ORM usage. It focuses on entity states, fetching strategies, caching, relationships, HQL, performance tuning, and commonly asked Hibernate interview questions.