Traditional way of storing objects in a database table, is to break up object into primitive data types, and store each primitive data in a table column. Application developer need to spend more time on writing mapping source code between class data members and table columns,etc… Situation worsens when relationship exists between objects, which need to be stored in database.
Hibernate provides solution for above problems.
Below is anatomy of Java Application, which uses Hibernate Framework.
1.Reduces size of code, hence development of Application is faster, which in turn controls cost of overall project.
When Hibernate is used, you need not write code to perform below routine activities
Connecting to database, retrieve individual columns from database table and creating object out of it , and vice versa.
2.Transaction Control: Hibernate has built in Transaction Management. A Transaction can be started, commited or rolled back by using Hibernate.
3.Automatic creation and updation of tables or columns. Required tables and columns are automatically created or updated, by provding hbm2ddl property in hbm file. Hibernate gets details of table names, column names, type,etc… from Hibernate Mapping file(i..e hbm.xml)
4.Provides HQL, Hibernate Query language, using which developer need to provide queries in terms of class names, and data members, instead of focusing on tables and columns.
5.Hibernate Caching, caches objects, so that when same object(s) are queried next, object from cache is returned, and database hit is avoided. This improves overall performance of Application.
In you may find, few program statements used again and again, like openSession(), beginTransaction(), commit(), rollBack(), close(),etc…which can be avoided multiple times, by better designing your application. Another alternative to further reduce Hibernate code, is to use combination of Spring and Hibernate.
Hibernate Framework further depends on JDBC, to interact with underlying database. Hence JDBC driver jar file need to be added to projects using Hibernate.
Such Framework is referred as ORM(Object Relational Mapping)