Q1. What are the configuration files in Hibernate ?
Ans. hibernate.cfg.xml ( Main Configuration File )
and *.hbm.xml files ( Mapping Files )
Q2. What entries we make in the hibernate config file if we are not using hbm files but Annotations ?
Ans. We configure Entity classes having annotated mappings.
Ans. We configure Entity classes having annotated mappings.
Q3. What are the contents of Hibernate configuration file ( hibernate.cfg.xml ) ?
Ans.
HBM Files ( Mapping )
DB Connection ( DB Connection String , User Name , Password , Pool Size )
SQL Dialect ( SQL variant to be generated )
Show SQL ( Show / No show SQL on Console )
Auto Commit ( True / False )
Q4. What is the purpose of dialect configured in Hibernate configuration file ?
Ans. It tells the framework which SQL variant to generate.
Q5. What is the use of hbm2ddl Configuration in Hibernate ?
Ans. This configuration specifies if hibernate should creates the Schema / Table on its own if the respective table is not found.
"update" doesn't create the table if it's not found whereas configuration set as "create" creates the schema automatically.
Ans. This configuration specifies if hibernate should creates the Schema / Table on its own if the respective table is not found.
"update" doesn't create the table if it's not found whereas configuration set as "create" creates the schema automatically.
Q6. How to configure second level cache in Hibernate ?
Ans.
1. Configure Provider class in Hibernate configuration file.
2. Add Cache usage tag ( read-only or read-write ) in mapping files ( hbm ).
3. Create an XML file called ehcache.xml and place in classpath which contains time settings and update settings, behavior of cache , lifetime and idletime of Pojos, how many objects are allowed.