Hibernate is a high-performance Object/Relational persistence and query service, which is licensed under open source GNU. It not only takes care of the mapping from Java classes to database tables, but also provides data query and retrieval facilities. Hibernate is an Object-Relational Mapping (ORM) solution for JAVA.
Following are the advantages of Hibernate:
● Hibernate takes care of mapping Java classes to database tables using XML files and without writing any line of code.
● Hibernate does not require an application server to operate.
● Provides simple querying of data.
● It provides simple APIs for storing and retrieving Java objects directly to and from the database.
● If there is change in the database or in any table, then you need to change the XML file properties only.
● Hibernate manipulates complex associations of objects of your database.
● Minimizes database access with smart fetching strategies.
Following are the databases which Hibernate supports:
● HSQL Database Engine
● Microsoft SQL Server Database
● Informix Dynamic Server
● Sybase SQL Server
Configuration object is the first Hibernate object that will be created in any Hibernate application. It is usually created only once during application initialization. It represents a configuration or properties file required by the Hibernate.
Following are the key components of configuration object in Hibernate:
● Database Connection ? This is handled through one or more configuration files supported by Hibernate. These files are hibernate.properties and hibernate.cfg.xml.
● Class Mapping Setup ? This component creates the connection between the Java classes and database tables.
Configuration object is used to create a SessionFactory object which configures Hibernate for the application using the supplied configuration file and allows Session object to be instantiated.
Yes, SessionFactory is a thread safe object and used by all the threads of an application in Hibernate.
There can be single SessionFactory object per database in Hibernate.
A Session is used to get a physical connection with a database. The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database.
Transaction represents a unit of work with the database and most of the RDBMS supports transaction functionality. Transactions in Hibernate are handled by transaction manager.
Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by query, and finally to execute it.