Master java skills

Hibernate

Hibernate is an ORM framework. ORM is abbreviation for Object-Relational Mapping. It is a design pattern that maps java objects to relational database objects.

Problems without ORM

What is the need of an ORM framework?

If we do not use ORM and still work with the realtional database. There are certain problems as metioned below:

  1. Granularity – There is no mapping between java classes/objects and database tables. There might be a possibility that no of classes are more than the number of database tables. Or vice versa.
  2. Inheritance – There is nothing in database analogous to Inheritance in Java. So, if we want to make such a relationship in database without using ORM, then it is a problem
  3. Identity Java support both Object equality and reference equality, whereas in database there is just primary key equality.
  4. Associations – In java association is done using object references whereas in database it is done using foreign key column.

Advantages

In order to overcome all these problems, ORM frameworks have been invented. Below are its advantages

  1. Java code interact with java objects only. There is no need to interact with database tables when we use ORM frameworks.
  2. JDBC is still the underlying api to interact with the database
  3. Java classes are directly mapped with database tables. And java attributes of a class are mapped with database columns. This is a great advantage because now there is a direct mapping of java objects and database tables.
  4. Automatic primary key generation along with other strategies is achieved.
  5. Database can be replaced very easily with minumum changes (in just one file).
  6. HQL and HCQL are not database dependent.
  7. Transaction management is done efficiently.
  8. Fast development can be done.
  9. Clarity between java code and database.
  10. Database tables are alligned with business requirements.

Java ORM Frameworks

  • Apache Cayenne – open source for java
  • Apache OpenJPA – open source for java
  • Data Nucleus – formerly known as JPOX
  • Ebean – open source framework
  • EclipseLink – Eclipse persistence platform
  • Enterprise JavaBeans
  • Enterprise Objects Framework – part of Apple Webobjects
  • Hibernate – open source, very widely used
  • Java Data Objects
  • JOOQ Object Oriented Querying (JOOQ)
  • Kodo
  • TopLink by Oracle
  • Caster