→ Hibernate is an ORM framework.
→ ORM stand for Object Relational Mapping it is a technique to map data of Object Domain into data of Relational Domain. In each Application, Application developers need to persist data into databases and need to fetch persistent data from databases. Java provides JDBC API for this task.
→ Main functionality of an ORM Framework is to persist objects and their relations into the database on behalf of Application Developers. For this ORM Frameworks require configuration & mapping information which can be provided in the form of XML or Annotations.
→ Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.
Commonly used classes and interfaces exposed by Hibernate for Application Developers –
→ Configuration object is used by the Hibernate to store Configuration Information in object form. Configuration Information represents data required by Hibernate to connect to a DB & information of classes that are to be managed by Hibernate.
→ It is a factory class which is used by Application Developer to create session. Apart from this, it can also be used to manage 2nd level caching of persistent object.
→ This is the main interface with which Application Developer interact. This interface provides methods for persisting object, creating transactions & query object.For each user a different session is created.
→ This interface is used by Application Developer to transact execution of queries.
→ This interface is used by the Application Developer to execute HQL (Hibernate Query Language) Queries. HQL is an Object based version of SQL used by Hibernate.
Steps required to persist objects using Hibernate :-
The persistent class objects of which are to be persisted is to be created. A persistent class has following characteristics
A mapping file need to be created to specify information of database tables in which data of objects is to be persisted.
A configuration file that contains database properties & references of mapping files need to be created.
A configuration object is created.
Using the configuration object a SessionFactory is obtained.
Using the SessionFactory, Session object is obtained.
Using the Session, objects are persisted.
Next TopicSteps to Create Eclipse IDE