Jump to content

Hibernate (framework)

From Alfawiki
Hibernate
Company typeOpen-source software
IndustrySoftware development
Founded2001
FounderGavin King and team at Cirrus Technologies
Area served
Worldwide
ProductsObject-relational mapping framework for Java
OwnerRed Hat
ParentRed Hat
Websitehibernate.org

Hibernate ORM (commonly referred to as Hibernate) is an object–relational mapping solution designed for the Java platform, created by Red Hat. It offers a structured approach to translate an object-oriented domain model into a relational database, effectively overcoming the challenges of object–relational impedance mismatch by substituting direct database interactions with advanced object manipulation methods.

Available as open-source software under the Apache License 2.0 (formerly distributed under the GNU Lesser General Public License 2.1), Hibernate's main capability lies in linking Java classes with database tables and converting Java data types into corresponding SQL types. Additionally, it facilitates data querying and retrieval by automating SQL statement creation, thereby reducing development effort.

Standards

Hibernate ORM complies with the official industry specifications, serving as a certified implementation of both the Jakarta Persistence (previously known as Java Persistence API) and Jakarta Data standards.

Mapping

The process of associating Java classes with database tables is managed through either XML configuration files or Java Annotations. When employing XML, Hibernate can produce initial source code templates for persistence classes and supports schema management using either configuration approach.

It accommodates intricate relationships such as one-to-many, many-to-many, and self-referential associations within class structures. Hibernate also allows customization of value type mappings to override default SQL types, supports mapping Java Enums as properties, and enables assigning a single property across multiple columns.

Explanation: In object-oriented applications, objects adhere to OOP design principles, whereas database entities follow normalization protocols, resulting in differences termed "object–relational impedance mismatch." Mapping addresses this discrepancy by defining how Java class instances correspond to specific database tables.

Hibernate Query Language (HQL)

Hibernate includes Hibernate Query Language (HQL), a query language inspired by SQL that allows developers to write queries targeting its data objects. An object-centric alternative called Criteria Queries enables dynamic query construction and filtering. HQL produces queries independent of any particular database dialect, simplifying maintenance when migrating between databases.

Persistence

Hibernate ensures seamless persistence for Plain Old Java Objects (POJOs). The essential requirement for any persistent class is the presence of a no-argument constructor, which does not need to be public. For optimal operation, careful overriding of the equals(Object obj) and hashCode() methods is advisable. Including an identifier property is recommended and expected to become mandatory in upcoming versions.

Collections of data are commonly stored using Java collection frameworks such as Set and List, with support for Java generics introduced from Java 5 onward. Hibernate offers configurable lazy loading for related collections, with lazy loading enabled by default since version 3.

Associated entities can be set up to cascade operations; for instance, a parent Album entity can propagate its save or delete actions automatically to its child Track entities.

Integration

Hibernate is compatible with both standalone Java applications and Java EE platforms, utilizing servlets, EJB session beans, and JBI components. Additionally, it has been incorporated into other programming languages; for example, Adobe integrated Hibernate into ColdFusion 9, which operates on J2EE application servers, introducing an abstraction layer along with new syntax and features in CFML.

Entities and components

Within Hibernate's framework, an entity refers to a self-contained object managed by Hibernate's persistence layer. Conversely, a component depends on an entity and can only be accessed through it—for instance, an Album entity containing Tracks as its component. Unlike J2EE implementations, Hibernate allows effortless switching between database systems.

History

Hibernate was created in 2001 by Gavin King and his team at Cirrus Technologies as a replacement for EJB2 entity beans, aiming to streamline persistence and introduce missing functionalities.

By early 2003, Hibernate2 brought substantial enhancements. Subsequently, JBoss, Inc. (now under Red Hat) recruited the primary developers to further develop the project.

The release of Hibernate 3.0 in 2005 introduced a new Interceptor/Callback framework, user-defined filters, and compatibility with JDK 5.0 Annotations. Starting with version 3.5.0, Hibernate became a certified implementation of the JPA 2.0 specification.

Later versions expanded its features:

  • December 2011: Hibernate Core 4.0 added multi-tenancy support, a ServiceRegistry for managing services, enhanced session management, improved integration capabilities, internationalization support, and clearer API distinctions.
  • December 2012 to December 2013: Releases from 4.1.9 through 4.3.0 incorporated support for JPA 2.1.
  • September 2015: Hibernate ORM 5.0.2 brought better bootstrapping processes, Java 8 compatibility, spatial data handling features, and Karaf integration.
  • October 2018: Version 5.3 delivered caching improvements aligned with JPA 2.2 inheritance.
  • December 2018: Version 5.4 introduced additional optimizations.
  • March 2022: Hibernate ORM 6.0 represented a major overhaul affecting APIs, annotations, and the query language.
  • October 2022: Version 6.1.4 provided incremental enhancements.
  • May 2025: The launch of Hibernate ORM 7.0 included support for Jakarta Persistence 3.2 and Jakarta Data 1.0.

These ongoing developments demonstrate Hibernate's dedication to advancing enterprise persistence technologies in line with evolving Java standards and organizational requirements.

Application programming interface

Hibernate's API is contained within the Java package .

org.hibernate.SessionFactory interface

The interface serves as the native counterpart to JPA's standard .

org.hibernate.Session interface

The interface defines a Hibernate session, which is the primary context for managing database entities. It oversees persistence states (transient, persisted, detached), retrieves persisted objects, and controls transaction boundaries.

A session generally persists for the duration of a logical database transaction and is neither thread-safe nor intended for concurrent use by multiple clients.

Software components

Hibernate comprises several essential modules, including:

  • Hibernate ORM (previously known as Hibernate Core) – the fundamental object-relational mapping framework designed for Java platforms
  • Hibernate Annotations (integrated into Hibernate Core from version 3.6 onward) – metadata facilitating the conversion between object-oriented and relational data models in accordance with JSR 317 Java Persistence API (JPA 2)
  • Hibernate EntityManager (incorporated into Core since version 5.2) – a JPA 2 persistence implementation that works alongside Annotations
  • Hibernate Envers – provides auditing and version control capabilities for persistent entities
  • Hibernate OGM (Object/Grid Mapper) – an extension enabling data storage within NoSQL databases
  • Hibernate Shards – supports horizontal partitioning across multiple relational databases; partial features included in Core 4.0 yet incompatible with other 4.x releases
  • Hibernate Search – embeds full-text search functionality through Apache Lucene within both Hibernate and JPA entity models
  • Hibernate Tools – a suite of Eclipse plugins and Ant tasks available as part of JBoss Developer Studio
  • Hibernate Validator – the official implementation of JSR 303 Bean Validation specification
  • Hibernate Metamodel Generator – an annotation processor that generates static metamodel classes for JPA 2 using the JSR 269 Pluggable Annotation Processing API
  • NHibernate – an object-relational mapping framework tailored for the .NET Framework

See also

Bibliography

External links