Why was Hibernate created?


Almost all contemporary, large applications are written in an object way. It is also true for J2EE applications, written in a typically object language: Java. As opposed to that, data are relational by nature and databases store them in a relational way. Both: object orientation for applications and relation of databases are totally natural. It is much faster to write object systems, they are also easier to design and divide tasks. Moreover, their implementation is usually very suitable for any kinds of alternations. Similarly, relational databases seem to be irreplaceable, mainly because they are very effective and introducing another model of storing databases soon is very unlikely.
Nevertheless, almost every application must store data somehow, therefore we have to combine in one system both: object orientation of its structure and relational model of storing data.

This is where the first problems appear:

We are forced to download data from a database many times, transfer them to an application and save the data converted by a system to a database. It is obviously possible to do it using SQL and Java programming language (JDBC). What will happen if one day we need to change a database e.g. from PostgreSQL to MySQL)?
Some constructions and commands working in PostgreSQL might not work in MySQL and the whole code will have to be modified.

In an application we usually have to define classes whose objects will serve us as "boxes" to store data for a short period of time as well as to pass on information between various layers and objects of the layers. It is obvious that the fields of the objects are usually the same as the fields of tables storing tuples describing these objects in a database. That is why e.g. an extention of a given type requires an alternation in two places. For instance, adding some information about a postal code to an address requires an extension of a table and defining an additional field in an object.

Here are some more technical problems: