Interview questions

Explain how to configure Hibernate.

<<Previous  Next>>

Hibernate - Explain how to configure Hibernate. - Feb 04, 2009 at 8:10 am by Vidya Sagar

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.

Hibernate - Explain how to configure Hibernate. - Nov 19, 2009 at 14:10 pm by Amit Satpute

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()

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

Also read

Explain the general flow of Hibernate communication with RDBMS?

The Hibernate configuration is to be loaded and creation of configuration object is done. The mapping of all hbm files will be performed automatically............

State the role of SessionFactory interface plays in Hibernate.

The SessionFactory is used to create Sessions. Each application is having usually only one SessionFactory............

<<Previous  Next>> 

Write your comment - Share Knowledge and Experience


Latest placement tests
Latest links
Home | Want a Job? Submit Key Skills | Employer login | My key skills | About us | Sitemap | Contact us