Hibernate is written in Java and is highly configurable through two types of configuration files. The first type of configuration file is named hibernate.cfg.xml. On startup,Hibernate consults this XML file for its operating properties,such as database connection string and password,database dialect,and mapping files locations. Hibernate searches for this file on the classpath. The second type of configuration file is a mapping description file (file extension *.hbm) that instructs Hibernate how to map data between a specific Java class and one or more database tables. Normally in a single application,you would have one hibernate.cfg.xml file,and multiple .hbm files depending upon the business entities you would like to persist.
Hibernate may be used by any Java application that requires moving data between Java application objects and database tables. Thus,it's very useful in developing two and three-tier J2EE applications. Integration of Hibernate into your application involves:
- Installing the Hibernate core and support JAR libraries into your project
- Creating a Hibernate.cfg.xml file to describe how to access your database
- Selecting appropriate SQL Dialect for the database.
- Creating individual mapping descriptor files for each persistable Java classes
Here are some commonly used classes of Hibernate.
1.5.1 SessionFactory (
SessionFactory is a thread safe (immutable) cache of compiled mappings for a single database. Usually an application has a single SessionFactory. Threads servicing client requests obtain Sessions from the factory. The behavior of a SessionFactory is controlled by properties supplied at configuration time.
1.5.2 Session (
A session is a connected object representing a conversation between the application and the database. It wraps a JDBC connection and can be used to maintain the transactions. It also holds a cache of persistent objects,used when navigating the objects or looking up objects by identifier.
1.5.3 Transaction (
Transactions are used to denote an atomic unit of work that can be committed (saved) or rolled back together. A transaction can be started by calling
session.beginTransaction() which actually uses the transaction mechanism of underlying JDBC connection,JTA or CORBA.A Session might span several Transactions in some cases.
A complete list of Hibernate APIs can be found at http://www.hibernate.org/hib_docs/v3/api/.