Hibernate Framework Hibernate Configuration 2 — Questions and Answers
Question 1: Which property configures the C3P0 connection pool minimum size in Hibernate?
- hibernate.c3p0.min_size (Correct answer)
- hibernate.pool.min
- c3p0.minPoolSize
- hibernate.connection.pool_size
Correct answer: hibernate.c3p0.min_size
The hibernate.c3p0.min_size property sets the minimum number of JDBC connections in the C3P0 pool.
Question 2: What is the role of the ServiceRegistry in modern Hibernate configuration?
- It bootstraps and wires all Hibernate services together (Correct answer)
- It manages HTTP sessions
- It handles database migrations
- It validates entity mappings
Correct answer: It bootstraps and wires all Hibernate services together
The ServiceRegistry is responsible for creating and managing Hibernate's internal services during bootstrapping.
Question 3: Which Hibernate property enables second-level cache?
- hibernate.cache.use_second_level_cache (Correct answer)
- hibernate.enable.l2cache
- hibernate.second.cache
- hibernate.cache.enabled
Correct answer: hibernate.cache.use_second_level_cache
Setting hibernate.cache.use_second_level_cache=true activates the second-level cache in Hibernate.
Question 4: What does hibernate.hbm2ddl.auto=validate do?
- Validates the schema against mappings without making changes (Correct answer)
- Creates missing tables
- Drops all tables on shutdown
- Updates schema to match entities
Correct answer: Validates the schema against mappings without making changes
The validate option checks that the database schema matches the Hibernate mappings and throws an error if they differ.
Question 5: Which annotation is used to mark a class as a JPA entity in Hibernate?
- @Entity (Correct answer)
- @Table
- @Persistent
- @Model
Correct answer: @Entity
The @Entity annotation marks a Java class as a JPA-managed persistent entity.
Question 6: What does the hibernate.format_sql property do?
- Formats SQL output with line breaks for readability (Correct answer)
- Validates SQL before execution
- Compresses SQL statements
- Converts SQL to a standard dialect
Correct answer: Formats SQL output with line breaks for readability
Setting hibernate.format_sql=true causes Hibernate to pretty-print SQL statements with indentation and line breaks.
Which property configures the C3P0 connection pool minimum size in Hibernate?