2010-10-12 16:41:27 -04:00
|
|
|
<!--
|
|
|
|
~ Hibernate, Relational Persistence for Idiomatic Java
|
|
|
|
~
|
2015-05-19 00:23:35 -04:00
|
|
|
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
|
|
|
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
2010-10-12 16:41:27 -04:00
|
|
|
-->
|
|
|
|
<body>
|
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<h2>Hibernate ORM aggregated API documentation</h2>
|
2010-10-12 16:41:27 -04:00
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<p>
|
|
|
|
Hibernate is a library for object/relation mapping (ORM). It provides:
|
|
|
|
</p>
|
2022-12-29 05:39:20 -05:00
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
a <em>native API</em> centered around {@link org.hibernate.SessionFactory} and
|
|
|
|
{@link org.hibernate.Session},
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
an implementation of the <em>Java (or Jakarta) Persistence API</em> (JPA),
|
|
|
|
where the equivalent central interfaces are {@link jakarta.persistence.EntityManagerFactory}
|
2023-07-21 14:51:18 -04:00
|
|
|
and {@link jakarta.persistence.EntityManager},
|
2022-12-29 05:39:20 -05:00
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
a set of <em>mapping annotations</em> which augment the O/R mapping annotations defined
|
2023-07-21 14:51:18 -04:00
|
|
|
by JPA, and which may be used with either API, and
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<em>compile-time tooling</em> for writing more type-safe code.
|
2022-12-29 05:39:20 -05:00
|
|
|
</li>
|
|
|
|
</ul>
|
2010-10-12 16:41:27 -04:00
|
|
|
|
|
|
|
<h3>Native API</h3>
|
2022-07-04 05:33:33 -04:00
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<p>
|
|
|
|
Along with {@link org.hibernate.SessionFactory} and {@link org.hibernate.Session}, applications
|
|
|
|
using the native API will often make use of the following interfaces:
|
|
|
|
</p>
|
2022-12-29 05:39:20 -05:00
|
|
|
<ul>
|
|
|
|
<li>{@link org.hibernate.cfg.Configuration} to configure and bootstrap Hibernate,</li>
|
|
|
|
<li>{@link org.hibernate.StatelessSession} for processes involving many entity instances,</li>
|
|
|
|
<li>{@link org.hibernate.Cache} to manage the second-level cache,</li>
|
2022-12-30 08:01:09 -05:00
|
|
|
<li>{@link org.hibernate.Transaction} to control local transactions,</li>
|
2022-12-29 05:39:20 -05:00
|
|
|
<li>{@link org.hibernate.query.Query} to execute HQL queries,</li>
|
|
|
|
<li>{@link org.hibernate.query.NativeQuery} to execute native SQL queries,</li>
|
2022-12-30 08:01:09 -05:00
|
|
|
<li>{@link org.hibernate.Filter} to manage filters,</li>
|
2022-12-29 05:39:20 -05:00
|
|
|
<li>{@link org.hibernate.query.criteria.HibernateCriteriaBuilder} to construct criteria queries,
|
|
|
|
and</li>
|
|
|
|
<li>{@link org.hibernate.relational.SchemaManager} to execute DDL in tests.</li>
|
|
|
|
</ul>
|
2010-10-12 16:41:27 -04:00
|
|
|
|
|
|
|
<h3>JPA</h3>
|
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<p>
|
|
|
|
The JPA interfaces are defined by the JPA specification. For details see the latest
|
|
|
|
<a href="https://jakarta.ee/specifications/persistence/">specification</a> along with the
|
|
|
|
<a href="https://jakarta.ee/specifications/persistence/2.2/apidocs/">API documentation</a>
|
|
|
|
for the package {@link jakarta.persistence}.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Note that since Hibernate 5.2, the native API extends the JPA API rather than wrapping it.
|
2022-12-30 13:34:19 -05:00
|
|
|
For example, <code>SessionFactory</code> extends <code>EntityManagerFactory</code>, and
|
2022-12-26 16:42:42 -05:00
|
|
|
<code>Session</code> extends <code>EntityManager</code>.
|
|
|
|
</p>
|
2023-01-31 05:54:11 -05:00
|
|
|
<p>
|
|
|
|
It's always possible to fall back from JPA interfaces to native APIs, by calling
|
|
|
|
{@link jakarta.persistence.EntityManager#unwrap entityManager.unwrap(Session.class)},
|
|
|
|
{@link jakarta.persistence.EntityManagerFactory#unwrap entityManagerFactory.unwrap(SessionFactory.class)},
|
|
|
|
or {@link jakarta.persistence.Query#unwrap query.unwrap(Query.class)}. In certain cases
|
|
|
|
it's also possible to access native functionality by passing a
|
|
|
|
{@linkplain org.hibernate.jpa.SpecHints JPA-defined} or
|
|
|
|
{@linkplain org.hibernate.jpa.HibernateHints Hibernate-defined} hint, at the cost of a
|
|
|
|
loss of type-safety.
|
|
|
|
</p>
|
2023-07-21 14:51:18 -04:00
|
|
|
<p>
|
|
|
|
These packages define additional extensions to the JPA APIs:
|
|
|
|
</p>
|
|
|
|
<ul>
|
|
|
|
<li>{@link org.hibernate.query.criteria} packages extensions to {@link jakarta.persistence.criteria}, and</li>
|
|
|
|
<li>{@link org.hibernate.metamodel.model.domain} packages extensions to {@link jakarta.persistence.metamodel}.</li>
|
|
|
|
</ul>
|
2022-07-04 05:33:33 -04:00
|
|
|
|
|
|
|
<h3>Mapping annotations</h3>
|
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<p>
|
|
|
|
The mapping annotations defined by the JPA specification provide a foundation for expressing
|
|
|
|
object/relational mappings in Hibernate and other JPA implementations.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The annotations in the package {@link org.hibernate.annotations} extend this foundation and
|
|
|
|
accommodate more specialized requirements. These annotation are not tied to the native API,
|
|
|
|
and may be used in conjunction with the JPA API.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The full power of Hibernate can only be unlocked via judicious use of these extra annotations.
|
|
|
|
</p>
|
2022-11-05 07:21:51 -04:00
|
|
|
|
2023-01-02 16:26:31 -05:00
|
|
|
<h3>XML-based mappings</h3>
|
|
|
|
|
|
|
|
Annotation-based mappings are the best choice for most users, but Hibernate offers XML-based
|
|
|
|
mappings as an alternative.
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
The JPA-standard XML schema is
|
|
|
|
<a href="https://jakarta.ee/xml/ns/persistence/orm/orm_3_0.xsd">orm_3_0.xsd</a>.
|
|
|
|
</li>
|
|
|
|
<li>
|
2023-01-04 11:21:32 -05:00
|
|
|
Hibernate extends this schema with some additional mapping elements. The extended schema is
|
2023-01-02 16:26:31 -05:00
|
|
|
<a href="https://hibernate.org/xsd/orm/mapping/mapping-3.1.0.xsd">mapping-3.1.0.xsd</a>.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Prior to the existence of JPA, Hibernate had its own format for XML-based mappings,
|
|
|
|
which still works, though it has not been improved in a long time. The DTD is
|
|
|
|
<a href="https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">hibernate-mapping-3.0.dtd</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
2022-12-30 13:34:19 -05:00
|
|
|
<h3>Bootstrapping Hibernate</h3>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
There are four basic ways to obtain an instance of Hibernate:
|
|
|
|
</p>
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
as a JPA <em>persistence provider</em>, by using
|
|
|
|
{@link jakarta.persistence.Persistence#createEntityManagerFactory},
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
by using the "simplified" {@link org.hibernate.cfg.Configuration} API,
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
for those who enjoy dirty hands, by using the APIs in {@link org.hibernate.boot}, or
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
in a <em>container environment</em> like
|
|
|
|
<a href="https://www.wildfly.org">WildFly</a> or <a href="https://quarkus.io">Quarkus</a>,
|
|
|
|
by letting the container take care of the bootstrap process and of injecting the
|
|
|
|
{@code EntityManagerFactory} or {@code SessionFactory}.
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p>
|
|
|
|
All major Java application servers and microservice frameworks come with built-in support for
|
|
|
|
Hibernate. Such container environments also typically feature facilities to automatically
|
|
|
|
manage the lifecycle of a {@code EntityManager} or {@code Session} and its association with
|
|
|
|
container-managed transactions.
|
|
|
|
</p>
|
2023-01-05 15:30:47 -05:00
|
|
|
<p>
|
2023-01-05 16:52:31 -05:00
|
|
|
Example configuration files for JPA and native usage may be found {@linkplain org.hibernate.cfg
|
|
|
|
here}. A comprehensive list of configuration properties understood by Hibernate may be found in
|
|
|
|
the class {@link org.hibernate.cfg.AvailableSettings}. Most sensible programs will only ever need
|
2023-01-05 15:30:47 -05:00
|
|
|
to use a tiny handful of them.
|
|
|
|
</p>
|
2022-12-30 13:34:19 -05:00
|
|
|
|
2023-07-21 14:51:18 -04:00
|
|
|
<h3>Annotations driving compile-time tooling</h3>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
The annotations defined by {@link org.hibernate.annotations.processing} instruct the Metamodel
|
|
|
|
Generator to {@linkplain org.hibernate.annotations.processing.CheckHQL validate HQL at compile
|
|
|
|
time}, and to automatically generate the implementation of
|
|
|
|
{@linkplain org.hibernate.annotations.processing.Find finder methods} and
|
|
|
|
{@linkplain org.hibernate.annotations.processing.HQL query methods}.
|
|
|
|
<p>
|
|
|
|
|
2022-12-29 05:39:20 -05:00
|
|
|
<h3>Popular extension points</h3>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Hibernate offers an enormous wealth of extension points for customizing almost any aspect of
|
|
|
|
its implementation. Most of these extension points are far too technical to be of interest to
|
|
|
|
the typical application developer.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
However, the following extension points are of quite general interest:
|
|
|
|
</p>
|
|
|
|
<ul>
|
2022-12-29 11:03:18 -05:00
|
|
|
<li>
|
|
|
|
{@link org.hibernate.boot.model.naming} allows the quantity of repetitive O/R mapping
|
|
|
|
metadata to be minimized via the use of naming strategies,
|
|
|
|
</li>
|
2022-12-30 05:29:08 -05:00
|
|
|
<li>
|
|
|
|
{@link org.hibernate.type.descriptor.jdbc} and {@link org.hibernate.type.descriptor.java}
|
|
|
|
contain the built-in {@code JdbcType}s and {@code JavaType}s for "compositional" basic
|
|
|
|
attribute type mappings,
|
|
|
|
</li>
|
2022-12-29 05:39:20 -05:00
|
|
|
<li>
|
|
|
|
{@link org.hibernate.usertype} defines support for user-defined custom attribute types,
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
{@link org.hibernate.generator} defines support for generated attribute values,
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
{@link org.hibernate.context.spi} defines support for context-bound "current" sessions
|
2023-01-01 12:21:07 -05:00
|
|
|
and contextual multi-tenancy, and
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
{@link org.hibernate.binder} allows for user-defined mapping annotations.
|
2022-12-29 05:39:20 -05:00
|
|
|
</li>
|
2022-12-30 13:34:19 -05:00
|
|
|
</ul>
|
|
|
|
<p>
|
|
|
|
More advanced extension points include:
|
|
|
|
</p>
|
|
|
|
<ul>
|
2022-12-30 19:05:13 -05:00
|
|
|
<li>
|
2023-01-04 11:21:32 -05:00
|
|
|
{@link org.hibernate.dialect} provides a framework for modelling dialects of SQL,
|
2022-12-30 19:05:13 -05:00
|
|
|
</li>
|
2022-12-29 05:39:20 -05:00
|
|
|
<li>
|
|
|
|
{@link org.hibernate.cache.spi} defines an SPI for integrating with second-level cache
|
|
|
|
providers,
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
{@link org.hibernate.engine.jdbc.connections.spi} defines an SPI for integrating with
|
|
|
|
JDBC connection pools.
|
|
|
|
</li>
|
|
|
|
</ul>
|
2023-01-04 11:21:32 -05:00
|
|
|
<p>
|
|
|
|
Finally, Hibernate ORM Core is itself a framework for advanced extensions like Hibernate Search,
|
|
|
|
Hibernate Reactive, and Envers, which do much more than just implementing a single well-defined
|
|
|
|
extension point. The starting points for such extensions are found in the packages
|
|
|
|
{@link org.hibernate.integrator.spi} and {@link org.hibernate.event.spi}.
|
|
|
|
</p>
|
2022-12-29 05:39:20 -05:00
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<h3>Package categories</h3>
|
2018-01-03 12:23:37 -05:00
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<p>
|
|
|
|
The organization of code into packages is based on the following classification:
|
|
|
|
</p>
|
2022-12-29 05:39:20 -05:00
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<strong>API packages</strong> include classes and interfaces which are used directly by
|
|
|
|
a typical application. These packages never have <code>spi</code> nor <code>internal</code>
|
|
|
|
in their name, and are not under the namespace <code>org.hibernate.testing</code>.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<strong>SPI packages</strong> include classes and interfaces which are used by integrators,
|
|
|
|
library developers, and framework developers to develop extensions to Hibernate, or to alter
|
|
|
|
its behavior in some way. These packages usually have <code>spi</code> in their name.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Some classes and interfaces are considered part of the internal implementation of Hibernate.
|
|
|
|
This category includes packages with <code>internal</code> in their name, along with any class
|
|
|
|
or interface annotated {@link org.hibernate.Internal @Internal}. Clients should avoid depending
|
|
|
|
directly on these types.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
The <code>hibernate-testing</code> module, and the namespace <code>org.hibernate.testing</code>
|
|
|
|
contain <strong>testing support</strong> used in the Hibernate test suite.
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-11-05 07:21:51 -04:00
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<h3>More information</h3>
|
2010-10-12 16:41:27 -04:00
|
|
|
|
2022-12-26 16:42:42 -05:00
|
|
|
<p>
|
|
|
|
Complete documentation may be found online at
|
|
|
|
<a href="http://hibernate.org/orm/documentation">http://hibernate.org/orm/documentation/</a>.
|
|
|
|
</p>
|
2010-10-12 16:41:27 -04:00
|
|
|
|
|
|
|
</body>
|