Hibernate is one of the most popular ORM solution for java application. Several java ORM tools like EJB, JPOX, Kodo etc exists but hibernate is used due to its simplicity. Hibernate is framework which is used to interact with database. It is a implementation of JPA(Java Persistence API) specification for ORM. Hibernate is started by Gavin King in 2001 and later acquired by JBoss. Now JBoss is part of RedHat. It is also supported by mvc spring framework so it is more popular. Next reason may be it’s complete object oriented nature. Where critics about paradigm mismatch between oop and relational databases are raised from developer community, the hibernate let us implement collection,inheritance, association and much features to realize object oriented environment.
What is ORM?
ORM is programming Technique used to map application domain model to relational database tables.
Transient Object is normal java object. The life of transient object is limited by the life of thread or process in which it is created.
When an object is passed to hibernate from java program then it is called persistence Object. It’s life is beyond the process that created and make it persistence. It can be later accessed and converted to Transient object.
Hibernate has numerous features which make it best for us to develop applications using databases.
- Auto DDL : While using hibernate we need not worry about table, relationship creation and data validation.
- Cache Support: Hibernate support different levels of cache which increases the efficiency and speed. In case where static table need to be fetched frequently I found cache extremely helpful.
- HQL: Hibernate has it’s own query language called HQL. HQL stands for Hibernate Query language and completely object oriented query. we need not to learn SQL and is beneficial if you do not know SQL. Main thing SQL statements are vendor specific some cases like data type int in mysql and number in sql server.
- Exception free: One of the worst experience with JDBC is Exceptions, where we must need to handle exception. But in Hibernate no any exception handling code is required. In fact it has changed all checked exceptions into unchecked. Also the database related exceptions are difficult to understand for java programmer.
- ORM support: It support all object oriented features like association and inheritance over the relational database.
- OGM support: OGM means Object Graph Mapping. After version 4.x.x hibernate can interact with non sql(Non relational) database like HBase and MongoDB.
- Primary key generation: In hibernate we can generate primary key automatically. Different algorithms for generating primary key are available.
- Search Support, Annotation support, connection pool support etc.