HIBERNATE Questions and Answers

Explain how to configure Hibernate?

Answer : 1
Hibernate uses a file by name hibernate.cfg.xml. This file creates the connection pool and establishes the required environment. A file named .hbm.xml is used to author mappings. The bootstrap action is configured by using Configuration interface.
There are two types of environment to configure hibernate:
1. Managed Environment: The definitions of database operations such as connections, transaction boundaries, security levels. This environment is provided by application servers such as Jboss,Weblogic,Websphere.
2. Non-managed Environment: The basic configuration template is provided by this interface. Tomcat is one of the examples that best supports this environment.

Answer :2
Programmatic configuration
The org.hibernate.cfg.Configuration instance can be instantiated directly by specifying XML mapping documents. If the mapping files are in the classpath, use addResource().
Configuration cfg = new Configuration()
An alternative way is to specify the mapped class and allow Hibernate to find the mapping document:
Configuration cfg = new Configuration()
org.hibernate.cfg.Configuration also allows you to specify configuration properties:
Configuration cfg = new Configuration()
.setProperty(“hibernate.dialect”, “org.hibernate.dialect.MySQLInnoDBDialect”)
.setProperty(“hibernate.connection.datasource”, “java:comp/env/jdbc/test”)
.setProperty(“hibernate.order_updates”, “true”);
Alternative options include:
Passing an instance of java.util.Properties to Configuration.setProperties().
Placing a file named hibernate.properties in a root directory of the classpath.
Setting System properties using java -Dproperty=value.
Including elements in hibernate.cfg.xml (this is discussed later).
Hibernate JDBC Properties: