ITWissen.info - Tech know how online

hibernate

Hibernate is a framework for mapping objects to relational databases for the Javaprogramming language - it is also called Object Relational Mapping Tool. Hibernate is implemented in the Java programming language and is freely available as open source under the link below. Hibernate uses the concept of reflection to determine so-called meta-information about the structure of objects and the underlying classes at runtime, which is then mapped to the tables of a database.

Hibernate implements the Java Persistence API (JPA) - a standard API for object-relational mappings - and provides additional functionality. This includes database queries using the Hibernate Query Language (HQL) and the programmatic ability to define queries using the Hibernate Criteria API. Hibernate can be integrated into a wide variety of software and system architectures such as rich client, client-server, Web applications, J2EE or Java Enterprise Edition (JEE). Hibernate was developed with support from JBoss Inc. and is also integrated into the JBoss application server. A ported version of Hibernate, NHibernate, is available for the .NET platform. This requires Fluent NHibernate and LINQ to NHibernate, which are available at the links below.

Object Relational Mapping (ORM) for structural mappings to relational databases

Object Relational Mapping (ORM) is a technique for mapping the objects of software written on the basis of object-oriented programming to the structures of a relational database. Incidentally, this technique is widely used because the use of purely object-oriented databases, OODB, has not yet become established in practice. Since relational formations cannot always be connected 1:1 with object-oriented structures, this is an approach for tools that support OR mapping. Besides commercial tools like Oracle Toplink, Hibernate is one of the best known and most developed persistence frameworks available as open source. Its use not only enables it to connect to most relational database systems but also takes into account aspects such as clusterability, caching and session management. Hibernate is characterized by extensive tool support as well as high performance.

Since Hibernate can be used with most available databases, access to the specific database is made performant by the fact that Hibernate supports different database dialects. The necessary information for accessing the specific database is collected in a separate configuration file, which is then loaded by Hibernate when the SessionFactory class is instantiated. The configuration file also contains the names of the classes for whose instances persistence is to be generated at runtime. Hibernate uses mechanisms similar to those of the also well-known Java Data Objects (JDO). For example, the type of ID generation or the hierarchy ofinheritance can be specified. Hibernate also offers functions such as a high-performance second level cache or transaction management similar to JDO. In addition to the already mentioned class SessionFactory, Session and Transaction continue to be central classes of the Hibernate framework.

Hibernate for transient objects

The Hibernate sessions organize the handling of persistent objects and are therefore of central importance. Each access to a database is a session and thus connects the Java application to the database. The states of the business objects are managed and the session is also responsible for persisting, loading as well as deleting them. To change persistent data, you have to work with transactions. It makes sense to have a maximum of one transaction object created by a session. Nested transactions are not supported. As soon as several transactions are open, they run completely isolated from each other. Each session has its own cache, which ensures the appropriate performance. Hibernate supports several implementations of transactions. JDBC transactions leverage the mechanism of the database being used. Java Database Connectivity (JDBC) is part of the Java Development Kit (JDK) and provides access to relational databases. Alternatively, the transaction mechanism of the application server can be used with Java Transaction API (JTA).

There are various options for querying databases with the Hibernate Query Language (HQL) and with queries and criterias. The syntax of HQL is similar to that of SQL and the JDO query language JDOQL. In addition, the query is implemented using SQL statements and the Criterias API provides an object-oriented interface for use in a Java application. Since version 3 of Hibernate, it is not only possible to read data and objects, but these can also be modified or deleted with a query.

Compared to comparable persistence frameworks such as the commercial Oracle Toplink or iBATIS, which is rather counted among the lightweight frameworks and is supported by Spring, Hibernate is characterized by an advanced state of development. In addition, good documentation and comprehensive tool support make implementing Hibernate much easier. Hibernate can be used directly by Java applications and servlet engines as well as integrated into an application server.

Informationen zum Artikel
Englisch: hibernate
Updated at: 04.04.2020
#Words: 1386
Links:
Translations: DE