In this tutorial we will learn Hibernate framework from the beginning.
Problem of JDBC
- Mapping Variables:
We have object in Java application but not in database so we need to map each and every persist member variables of the object to the table column of database.
- Mapping Relationships:
If there are relationship between two java object then we need to create Primary key and Foreign key in database table for relationship of java object.
- Handling Data Types:
Some cases the data type is different of table from the variable of object, so manually data conversion is required.
For ex: boolean type is present in java object but most of databases not supported boolean, there might be char,int, binary etc
- Managing Object State Changes:
In JDBC managing the object state change management is very complex. Lets see the scenario, we have retrieved the data and populated to the java object and then modified some property value,
now if we want to persist those values again then we need to handle mapping those property value to the table.
What is Object-Relational Mapping(ORM)
It is a programming technique for converting object-type data of an object oriented programming language into database tables.
What is Hibernate
- Hibernate is lightweight, free open source and object-relational mapping (ORM) framework for Java.
- Hibernate is responsible for making Java persisting objects by storing it in a database.
Advantages of Hibernate
- Database Independent: Hibernate can work well with any RDMS like Oracle,DB2,MySql.
- SQL not required: SQL knowledge is not required as Hibernate is a set object and the table is treated as an object here
- Cache Support: Hibernate support caching mechanism(First level and Second Level), the data can be placed in the cache for faster performance.
- JPA Support: It implements JPA(Java Persistence API). It means hibernate follows the rules which specified in JPA specification.
- Managing Data Type: Hibernate converts the object data type to the table data type.
- Hibernate has Multiple Projects.
- It compliance with new EJB3 Persistence Standards.
- It supports both xml mapping and Java 5 Annotations
- It supports both the Hibernate API and the EJB3 Persistence API