Hibernate Framework Hibernate Configuration 1 — Questions and Answers
Question 1: Which file is the primary XML configuration file for Hibernate?
- hibernate.cfg.xml (Correct answer)
- hibernate.properties
- persistence.xml
- beans.xml
Correct answer: hibernate.cfg.xml
hibernate.cfg.xml is the standard XML configuration file where database connection and mapping details are specified.
Question 2: Which property in hibernate.cfg.xml specifies the JDBC URL?
- hibernate.connection.url (Correct answer)
- hibernate.jdbc.url
- hibernate.datasource.url
- hibernate.db.url
Correct answer: hibernate.connection.url
The hibernate.connection.url property holds the JDBC connection URL for the database.
Question 3: What is the purpose of the hibernate.dialect property?
- Specifies the SQL dialect for the target database (Correct answer)
- Sets the connection pool size
- Configures the cache provider
- Defines the transaction manager
Correct answer: Specifies the SQL dialect for the target database
hibernate.dialect tells Hibernate which SQL variant to generate for the specific database vendor being used.
Question 4: Which class is used to build a SessionFactory from a Configuration object?
- SessionFactory
- Configuration.buildSessionFactory() (Correct answer)
- HibernateUtil
- Session.openFactory()
Correct answer: Configuration.buildSessionFactory()
The buildSessionFactory() method on the Configuration object creates a SessionFactory instance.
Question 5: What does setting hibernate.show_sql=true do?
- Logs all generated SQL statements to the console (Correct answer)
- Validates SQL syntax before execution
- Enables SQL formatting in results
- Caches SQL queries
Correct answer: Logs all generated SQL statements to the console
Setting hibernate.show_sql=true causes Hibernate to print every SQL statement it executes to standard output.
Question 6: Which hibernate.hbm2ddl.auto value drops and recreates the schema on startup?
- create-drop
- create (Correct answer)
- update
- validate
Correct answer: create
The 'create' value drops the existing schema and creates a fresh one each time Hibernate initializes.
Which file is the primary XML configuration file for Hibernate?