Hibernate ORM

Why Hibernate ORM?

We know Enterprise applications use persistent systems to store the data for later processing. There are various type persistent system like Relational databases and Object databases. Many object oriented programming languages make use of relational databases for data persistent. Java is one of them. Java provides JDBC API to deal with Relational Database Systems (RDBMS) and it works quite well until data model of any application is very complex.

But using JDBC API we need to take care:

  • Mapping of business objects to the database tables
    • map object fields to tables columns before inserting, retrieving of updating the data
    • Eg: employeeName field of Employee class to emp_name column of EMPLOYEE table
  • Writing SQL queries and sometime complex queries like JOINs
  • Managing object relationship in term of tables
  • There are various other problems when it comes to mapping objects to the relational database tables
  • Some of these problems collectively known as Object-Relational Impedance Mismatch

Object-Relational Impedance Mismatch (from hibernate.org)

'Object-Relational Impedance Mismatch' (sometimes called the 'paradigm mismatch') is just a fancy way of saying that object models and relational models do not work very well together. RDBMSs represent data in a tabular format, whereas object-oriented languages, such as Java, represent it as an interconnected graph of objects.

Loading and storing graphs of objects using a tabular relational database exposes us to 5 mismatch problems…

  • Granularity
  • Subtypes (inheritance)
  • Identity
  • Association
  • Data Navigation

A system/framework/tool is needed that can

  • Provide Object-Relational Mapping
  • Solve Object-Relational Impedance Mismatch
  • Provide rich query capability which can deal with complex queries
  • Support concurrency
  • Manage transactions

Hibernate ORM provides all the features mentioned above.

What is Hibernate ORM?

A framework for persisting / saving Java objects in a database. The official website of hibernate frameworks is www.hibernate.org

Benefites of Hibernate ORM

  • Hibernate handles all of the low-level SQL
  • Minimizes the amount of JDBC code you have to develop
  • Hibernate provides the Object-to-Relational Mapping (ORM)
  • Solves Object Relational Mapping Impedance Mismatch problems
  • The developer defines mapping between Java class and database table
Footer with Map