Hibernate Overview
Topics
- What is Hibernate?
- Benefits of Hibernate
- Code Snippets
What is Hibernate?
- A framework for persisting/ saving java objects into a database
- www.hibernate.org
At high level you will have Java Application, it will make use of Hibernate framework for saving and retrieving data from the database.
Benefits of Hibernate
- Hibernate handles all the low-level SQL
- Minimize the amount of JDBC code you have to develop
- Hibernate provides the Object to Relational Mapping (ORM)
Entity (Java) = Table (Sql)
Mapping can be done via configuration file (XML file) or Java Annotations
No need to write sql quires just call the special method (session) which is provided by hibernate.
“theID” is the primary key which session returns after saving the java object into db
While retrieving Hibernate will do all the low level work of doing the query, getting the actual data, constructing the object and returning it back to your program.
For getting all of the Students objects from the table we can make use of something called “Hibernate Query Language (HQL)“.
Hibernate and JDBC
Hibernate ORM is an object-relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database.
Hibernate relationship with JDBC (Java Database Connectivity)
- Hibernate actually uses JDBC for all database communications
- Hibernate is another layer of abstraction on top of JDBC
- So when your application uses Hibernate framework, your app will store and retrieve objects using hibernate api, in the background hibernate does all of the low level JDBC work and submitting sql queries and so on.
- Hibernate does a lot of low level work for you, but In the background it all goes to the standard JDBC Api.
- When we config hibernate to talk to the Database we will actually configure to make use of JDBC driver to communicate to the database.