Hibernate - Explain how to configure Hibernate.

Explain how to configure Hibernate.

- 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.

Explain how to configure Hibernate.

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()
.addResource("Item.hbm.xml")
.addResource("Bid.hbm.xml");
- An alternative way is to specify the mapped class and allow Hibernate to find the mapping document :
Configuration cfg = new Configuration()
.addClass(org.hibernate.auction.Item.class)
.addClass(org.hibernate.auction.Bid.class);
-org.hibernate.cfg.Configuration also allows you to specify configuration properties :
Configuration cfg = new Configuration()
.addClass(org.hibernate.auction.Item.class)
.addClass(org.hibernate.auction.Bid.class)
.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 <property> elements in hibernate.cfg.xml (this is discussed later).

Hibernate JDBC Properties :
hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.connection.pool_size
Hibernate - What is a HibernateTemplate?
What is a HibernateTemplate? - HibernateTemplate is a helper class that is used to simplify the data access code.
Hibernate - What are the benefits of HibernateTemplate?
What are the benefits of HibernateTemplate? - HibernateTemplate, which is a Spring Template class, can simplify the interactions with Hibernate Sessions...
Hibernate - What is Hibernate proxy?
What is Hibernate proxy? - Mapping of classes can be made into a proxy instead of a table....
Post your comment