2020-04-01 14:47:41 -04:00
= 6.0 Migration Guide
2015-08-20 15:29:48 -04:00
:toc:
2022-01-05 17:24:11 -05:00
:toclevels: 4
:docsBase: https://docs.jboss.org/hibernate/orm/6.0
:userGuideBase: {docsBase}/userguide/html_single/Hibernate_User_Guide.html
:javadocsBase: {docsBase}/javadocs
:fn-converter: footnote:converter[Think `AttributeConverter`]
2015-08-20 15:29:48 -04:00
2020-04-01 14:47:41 -04:00
This guide discusses migration from Hibernate ORM version 6.0. For migration from
2015-08-20 15:29:48 -04:00
earlier versions, see any other pertinent migration guides as well.
2016-05-03 13:21:11 -04:00
2018-01-17 23:02:35 -05:00
2022-01-05 17:24:11 -05:00
== Jakarta Persistence
2021-09-23 17:34:44 -04:00
6.0 moves from Java Persistence as defined by the Java EE specs to
Jakarta Persistence as defined by the Jakarta EE spec. The most immediate
impact of this change is that applications would need to be updated to use
the Jakarata Persistence classes (`jakarta.persistence.*`) instead of the Java
Persistence ones (`javax.persistence.*`).
The Jakarta spec also renames the JPA settings (again, from `javax.persistence.*` to
'jakarta.persistence.*') and defines a new set of XSD namespaces for `orm.xml` and
`persistence.xml` files.
Jakarta provides a https://github.com/eclipse/transformer[transformer]
tool which, along with appropriate "rules", will transform a project from Java Persistence to
Jakarta Persistence. This can update package names in source, settings, xsd references and more.
NOTE: As far as the XSD and setting changes, Hibernate does support both sets as a temporary aid
2021-12-31 17:21:32 -05:00
in migration. It logs a deprecation warning when the Java EE variants are used. See the `rules/`
directory in the project root for the configuration used to migrate Hibernate itself.
2022-01-05 17:24:11 -05:00
== Java 11
2021-12-31 17:21:32 -05:00
With 6.0, Hibernate ORM has moved to expect Java 11 as its baseline version
2021-09-23 17:34:44 -04:00
2021-12-31 17:21:32 -05:00
[[read-jdbc]]
2022-01-05 17:24:11 -05:00
== Reading from JDBC
One of the main reasons for 6.0 development was the move from reading results
from the JDBC `ResultSet` by name (read-by-name) as done in previous versions
of Hibernate, to reading the results by position (read-by-position).
Throughput testing of Hibernate showed that its use of read-by-name was its limiting factor
in any further scaling in terms of throughput - much of the issue was actually the call into
the `ResultSet`. We like to improve performance all the time :)
This change, along with <<sql>>, helped achieve this goal.
As discussed in <<type>> though, this change has a very big impact on Hibernate's mapping type system
[[sql]]
== Generated SQL
1. Column aliases are no longer generated.
2. Column references are "unique-d".
3. Better definition of joins
4. Better determination of unnecessary joins (secondary tables, inheritance tables)
2021-09-23 17:34:44 -04:00
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
== Bulk SQM against entities mapped to multiple tables
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
// todo (6.0) - @Christian - can you add some info here?
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
[[identifier]]
== Identifier as Object
Previous versions of Hibernate required that all identifier types implement `Serializable`. 6.0
removes this restriction - identifiers can be any `Object`.
This change affects many api and spi methods previously defined using `Serializable`.
[[id-gen-type]]
== @IdGeneratorType
6.0 adds a new `@IdGeneratorType` annotation that allows better, type-safe way
to define custom generators to use for identifier generation.
// todo (6.0 - @Steve - need to add content about this to the User Guide
2021-09-23 17:34:44 -04:00
2021-12-31 17:21:32 -05:00
[[type]]
2022-01-05 17:24:11 -05:00
== Type system
2018-11-14 11:14:30 -05:00
2021-12-31 17:21:32 -05:00
Another change is to generally modernize Hibernate's mapping annotations and make them
more type-safe.
2021-10-06 10:51:57 -04:00
2021-12-31 17:21:32 -05:00
We decided this is the right time since 6.0 is a major release and most of the type-related
contracts were already changing to implement the <<read-jdbc,read-by-position>> changes.
2021-10-06 10:51:57 -04:00
2021-12-31 17:21:32 -05:00
One part of this work was the removal of various String-based approaches for specifying Types to use from annotations, including
the removal of `@Type`, `@AnyMetaDef`, `@AnyMetaDefs`, `@MapKeyType`, @TypeDef` and `@TypeDefs`, as well as
removing annotation attributes accepting the type to use as a String (e.g. `org.hibernate.annotations.CollectionType#type`)
2020-04-15 09:03:21 -04:00
2022-01-05 17:24:11 -05:00
The https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#domain-model[User Guide]
covers the details of mapping your domain model.
2020-04-15 09:03:21 -04:00
2021-12-31 17:21:32 -05:00
[[rename-java-type]]
2022-01-05 17:24:11 -05:00
=== Renaming of JavaTypeDescriptor contract
2018-11-14 11:14:30 -05:00
2021-12-31 17:21:32 -05:00
The interface `org.hibernate.type.descriptor.java.JavaTypeDescriptor` has been renamed to
`org.hibernate.type.descriptor.java.JavaType`
2018-11-14 11:14:30 -05:00
2021-08-24 12:59:58 -04:00
2021-12-31 17:21:32 -05:00
[[rename-jdbc-type]]
2022-01-05 17:24:11 -05:00
=== Renaming of SqlTypeDescriptor contract
2021-08-24 12:59:58 -04:00
2021-12-31 17:21:32 -05:00
The interface `org.hibernate.type.descriptor.sql.SqlTypeDescriptor` has been renamed to
2022-01-05 17:24:11 -05:00
`org.hibernate.type.descriptor.jdbc.JdbcType`.
2021-09-28 02:15:07 -04:00
2021-08-24 12:59:58 -04:00
2021-12-31 17:21:32 -05:00
[[basic-type]]
2022-01-05 17:24:11 -05:00
=== Basic types
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
Basic mappings are no longer configurable through the `BasicType` contract. Instead,
users configure the different aspects of mapping the basic value to the database -
2021-11-29 09:49:13 -05:00
2021-12-31 17:21:32 -05:00
* `JavaType`
* `JdbcType`
2022-01-05 17:24:11 -05:00
* `BasicValueConverter` {fn-converter}
2021-12-31 17:21:32 -05:00
* `MutabilityPlan`
2021-11-29 09:49:13 -05:00
2021-12-31 17:21:32 -05:00
This also made the various implementations of `BasicType` obsolete, thus they have been removed.
`NamedBasicTypeImpl` takes the role of all the previous specific implementations by wrapping a
`JdbcType` and `JavaType`.
2021-11-29 09:49:13 -05:00
2022-01-05 17:24:11 -05:00
The `StandardBasicTypes` class previously exposed `BasicType` instance fields, which now have been
replaced with fields of the type `BasicTypeReference`. APIs that previously accepted just a `BasicType`
have been adapted to also accept a `BasicTypeReference` which allows for uses of `StandardBasicType`
fields to stay mostly source compatible.
See https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#basic for details.
==== UserType
2022-01-06 22:45:14 -05:00
`UserType` is still supported, and is specified using the new `Type` annotation.
2022-01-05 17:24:11 -05:00
See https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#basic-mapping-custom for details.
==== Boolean converters
Hibernate now provides standard `AttributeConverter` implementations for handling different database representations
as boolean values in the domain model:
`YesNoConverter`:: Handles values stored in the database as either `Y` or `N`. Replaces the removed `YesNoBooleanType` (`yes_no`)
`TrueFalseConverter`:: Handles values stored in the database as either `T` or `F`. Replaces the removed `TrueFalseBooleanType` (`true_false`)
`NumericBooleanConverter`:: Handles values stored in the database as either `1` or `0`. Replaces the removed `NumericBooleanType` (`numeric_boolean`)
E.g.
```
@Type(type="yes_no")
boolean isActive;
```
becomes
```
@Convert(converter=YesNoConverter.class)
boolean isActive;
```
In fact, if your application consistently maps booleans to the same database representation you can
even register one as an auto-apply converter.
See https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#basic-boolean for details.
=== Embeddables / components
2021-11-29 09:49:13 -05:00
2022-01-05 17:24:11 -05:00
Mapping of embeddables had a few changes as well.
2021-11-29 09:49:13 -05:00
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
==== Different embeddable mappings
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
Multiple component mappings for the same Java class with different property mappings is no
longer supported. Every property mapping combination should have its own Java class
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
==== EmbeddableInstantiator
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
6.0 introduces the new `EmbeddableInstantiator` contract.
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
`EmbeddableInstantiator` supports constructor-injection! Note, however, that embeddables used as
identifiers cannot use constructor injection.
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
See https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#embeddable-instantiator for details.
2021-11-17 05:06:01 -05:00
2022-01-05 17:24:11 -05:00
=== Plural attributes
2022-01-06 22:45:14 -05:00
6.0 defines 2 main ways to influence collection mapping:
2022-01-05 17:24:11 -05:00
2022-01-06 22:45:14 -05:00
`@CollectionType`:: see <<collection-type-ann>>
`@CollectionTypeRegistration`:: see <<collection-type-reg-ann>>
[[collection-type-ann]]
2022-01-05 17:24:11 -05:00
==== `@CollectionType`
The `@CollectionType` annotation is kept from 5.x. However, where it used to define
```
String type();
```
it now defines
```
Class<? extends UserCollectionType> type();
```
The type to use must be a `UserCollectionType` (can no longer be a `CollectionType`) and
it no longer works with type-definitions. See <<type>> for further discussion of general type changes.
See https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#collection-type-ann
for details of using `@CollectionType`
2022-01-06 22:45:14 -05:00
[[collection-type-reg-ann]]
==== `@CollectionTypeRegistration`
2022-01-05 17:24:11 -05:00
2022-01-06 22:45:14 -05:00
Allows to "auto apply" a `UserCollectionType` whenever Hibernate encounters a particular
plural attribute classification
2022-01-05 17:24:11 -05:00
2022-01-06 22:45:14 -05:00
See https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#collection-type-reg-ann
for details of using `@CollectionTypeRegistration`
2022-01-05 17:24:11 -05:00
=== Misc
* The default type for `Duration` was changed to `NUMERIC` which could lead to schema validation errors
2021-11-24 12:21:29 -05:00
2021-12-31 17:21:32 -05:00
[[query]]
2022-01-05 17:24:11 -05:00
== Query
2022-01-10 13:25:08 -05:00
// todo (6.0) - Query parameter binding overloads accepting `Type`, `BindableType`
2022-01-05 17:24:11 -05:00
// todo (6.0) - addition of parameter binding overloads accepting Class - AttributeConverter, UserType, Java Type (resolved from JavaTypeRegistry), ...
[[query-stream]]
=== Stream
`jakarta.persistence.Query#getResultStream()` and `org.hibernate.query.Query#stream()` no longer
return a `Stream` decorator. In order to close the underlying IO resources, it is now necessary to
explicitly call the `Stream#close()` method.
This change makes the Streams returned by Hibernate behave as defined in the JDK
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/stream/Stream.html[Stream]
documentation, which is quite explicit about the need for an explicit call to `close` by the user
to avoid resource leakages.
[[query-iterate]]
=== Iterate
The `Query#iterate()` method has been removed. The alternative is to use one of
* `Query#stream()`
* `Query#getResultStream()`
* Get the `Iterator` from `List` returned by `Query#list()` / `Query#getResultList()`
2021-12-31 17:21:32 -05:00
[[query-sqm]]
2022-01-05 17:24:11 -05:00
== SQM (HQL/Criteria)
Another major change in 6.0 is the move to a dedicated tree structure to model
HQL and Criteria queries. This tree structure is called the Semantic Query Model, or
SQM for short.
2021-12-31 17:21:32 -05:00
todo (6.0) - cover functions
todo (6.0) - cover new temporal capabilities
todo (6.0) - cover new syntaxes
todo (6.0) - cover bulk manipulation query handling
[[query-sqm-rows]]
==== Result "rows"
Queries that use joins without specifying a select clause (e.g. `from Person p join p.address`)
used to return a `List<Object[]>`. Starting with 6.0, such a query instead returns
`List<Person>`
The HQL query `select p, a from Person p join p.address a` returns instead a `List<Object[]>`.
2021-11-17 05:06:01 -05:00
```
2021-12-31 17:21:32 -05:00
List<Person> result = session.createQuery("from Person p join p.address").list();
List<Object[]> results = session.createQuery("select p, a from Person p join p.address a").list();
```
2021-11-17 05:06:01 -05:00
2021-11-24 12:21:29 -05:00
2021-12-31 17:21:32 -05:00
[[query-sqm-pass-thru]]
2022-01-05 17:24:11 -05:00
==== Pass-through tokens
2021-11-17 05:06:01 -05:00
2021-12-31 17:21:32 -05:00
The use of plain HQL identifiers in e.g. functions which couldn't be interpreted as an attribute of a `FROM` root
were passed through as-is to SQL in Hibernate 5.x which was dropped in 6.0 because we believe this is unsafe
and might lead to surprising results. HQL queries that relied on this, need to be changed and use the newly introduced
`sql` function, which allows passing through the content of a string literal to SQL.
2021-11-17 05:06:01 -05:00
2021-12-31 17:21:32 -05:00
An HQL query like `select substring( e.description, 21, 11, octets ) from AnEntity e`, which relies on this for passing through `octets`
can be migrated to `select substring( e.description, 21, 11, sql('octets') ) from AnEntity e`.
2021-11-17 05:06:01 -05:00
2021-12-31 17:21:32 -05:00
[[query-sqm-distinct]]
2022-01-05 17:24:11 -05:00
==== DISTINCT
2021-12-22 07:30:51 -05:00
Starting with Hibernate ORM 6 it is no longer necessary to use *distinct* in JPQL and HQL
to filter out the same parent entity references when join fetching a child collection.
2021-12-31 17:21:32 -05:00
The returning duplicates of entities are now always filtered by Hibernate.
2021-12-22 07:30:51 -05:00
Which means that for instance it is no longer necessary to set `QueryHints#HINT_PASS_DISTINCT_THROUGH` to `false`
in order to skip the entity duplicates without producing a `distinct` in the SQL query.
2021-12-31 17:21:32 -05:00
From Hibernate ORM 6, `distinct` is always passed to the SQL query and the flag `QueryHints#HINT_PASS_DISTINCT_THROUGH`
2021-12-22 07:30:51 -05:00
has been removed.
2021-10-01 16:15:23 -04:00
2022-01-05 17:24:11 -05:00
==== Association Comparisons
2021-12-31 17:21:32 -05:00
Previously Hibernate did allow comparing an association with an FK value like `... where alias.association = 1`
or `... where alias.association = alias.association.id` or even `... where alias.association = :param` where `param`
is bound to an integer `1`. This was supported prior to Hibernate 6.0 if the foreign key for the association is an integer.
The right way to do this is de-referencing the association by the FK attribute `... where alias.association.id = 1`
which is guaranteed to not produce a join, or use an entity reference for `... where alias.association = :param`
where `param` is bound to `entityManager.getReference(EntityClass.class, 1)`.
[[query-sqm-psuedo-attr]]
2022-01-05 17:24:11 -05:00
==== Collection psuedo-attributes
2021-12-31 17:21:32 -05:00
Prior to 6.0, it was possible to de-reference special properties on plural attributes like `size` which was dropped.
The special properties lead to confusion and were sometimes ambiguous. The replacement is the function syntax.
size::
The collection size can be determined by using the `size( pluralAttribute )` function instead
elements::
The collection elements can be referred to by using the `value( pluralAttribute )` function instead
indices::
The collection indices can be referred to by using the `index( pluralAttribute )` or `key( pluralAttribute )` function instead
index::
The collection index can be referred to by using the `index( pluralAttribute )` or `key( pluralAttribute )` function instead
maxindex::
The collection maximum index can be determined by using the `maxindex( pluralAttribute )` function instead
minindex::
The collection minimum index can be determined by using the `minindex( pluralAttribute )` function instead
maxelement::
The collection maximum element can be determined by using the `maxelement( pluralAttribute )` function instead
minelement::
The collection minimum element can be determined by using the `minelement( pluralAttribute )` function instead
[[query-native]]
2022-01-05 17:24:11 -05:00
== NativeQuery
As `NativeQuery` extends from `Query`, all the changes listed in <<query>> also apply
to `NativeQuery`.
Some additional changes apply specifically to `NativeQuery`
[[query-ordinal-param]]
=== Ordinal Parameters binding
HQL ordinal parameter binding is 1-based, this means that queries like
```
s.createQuery( "select p from Parent p where id in ?0", Parent.class );
query.setParameter( 0, Arrays.asList( 0, 1, 2, 3 ) );
```
that uses a 0-based positional binding are not supported, and they should be changed to the following
```
s.createQuery( "select p from Parent p where id in ?`", Parent.class );
query.setParameter( 1, Arrays.asList( 0, 1, 2, 3 ) );
```
[[proc-call-nativequery]]
=== Callable via NativeQuery
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
Using `NativeQuery` to call SQL functions or procedures is no longer supported.
Given the `NamedNativeQuery`-
2021-10-01 16:15:23 -04:00
```
@NamedNativeQuery(
name = "fn_person_and_phones",
query = "{ ? = call fn_person_and_phones( ? ) }",
callable = true,
resultSetMapping = "person_with_phones"
)
```
the code
```
scope.inTransaction(
entityManager -> {
try {
List<Object[]> postAndComments = entityManager.createNamedQuery("fn_person_and_phones" ).setParameter( 1, 1L ).getResultList();
```
is going to throw an `IllegalArgumentException`.
2021-12-23 18:21:48 -05:00
If you want to retain the named version, you can change the definition to
```
@NamedStoredProcedureQuery(
name = "fn_person_and_phones",
procedureName = "fn_person_and_phones",
resultSetMapping = "person_with_phones",
hints = @QueryHint(name = "org.hibernate.callableFunction", value = "true"),
parameters = {
@StoredProcedureParameter(type = Long.class)
}
)
```
and call this like
```
List<Object[]> postAndComments = entityManager.createNamedStoredProcedureQuery( "fn_person_and_phones" ).setParameter( 1, 1L ).getResultList();
```
or not define the stored procedure and use this code
2021-10-01 16:15:23 -04:00
```
List<Object[]> postAndComments = entityManager.createStoredProcedureQuery( "fn_person_and_phones", "person_with_phones" ).setParameter( 1, 1L ).getResultList();
```
2022-01-05 17:24:11 -05:00
[[proc-call-param]]
== ProcedureCall Parameters
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
For parameters defined on a ProcedureCall as accepting binding (IN and INOUT), a distinction is now
made between whether `setParameter` is called or not. If `setParameter` was called, whatever value
was set by the user is passed to the database. If it was not called, Hibernate will not
set any value which triggers the default value defined on the database procedure argument be used
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
== Interceptor
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
The signature of the `#onSave` method has been changed from
2021-12-31 17:21:32 -05:00
```
2022-01-05 17:24:11 -05:00
boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
2021-12-31 17:21:32 -05:00
```
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
to
2021-11-23 12:16:48 -05:00
2021-12-31 17:21:32 -05:00
```
2022-01-05 17:24:11 -05:00
boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
2021-12-31 17:21:32 -05:00
```
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
to account
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
== Removals
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
=== Legacy Hibernate Criteria API
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
The legacy Hibernate Criteria API which was deprecated back in Hibernate 5.x and removed in 6.0.
Usually, all queries using the legacy API can be modeled with the JPA Criteria API.
In some cases it is necessary to use the Hibernate JPA Criteria extensions.
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
=== JMX integration
2021-11-23 12:16:48 -05:00
2022-01-05 17:24:11 -05:00
Hibernate no longer provides built-in support for integrating itself with JMX environments.
2021-09-27 14:19:54 -04:00
2022-01-05 17:24:11 -05:00
=== JACC integration
2021-09-27 14:19:54 -04:00
2022-01-05 17:24:11 -05:00
Hibernate no longer provides built-in support for integrating itself with JACC environments.
2021-11-24 10:25:23 -05:00
2021-11-30 07:35:07 -05:00
2022-01-05 17:24:11 -05:00
=== Previously Deprecated features:
* 'hibernate.classLoader.application', 'hibernate.classLoader.resources', 'hibernate.classLoader.hibernate' and 'hibernate.classLoader.environment': use 'hibernate.classLoaders' instead.
* 'hibernate.hbm2dll.create_namespaces': use 'jakarta.persistence.create-database-schemas' or 'hibernate.hbm2ddl.create_namespaces'
// todo (6.0) - surely there are more than this...
2021-11-30 07:35:07 -05:00
2022-01-05 17:24:11 -05:00
== Width-first fetch determination
2021-11-30 07:35:07 -05:00
2022-01-05 17:24:11 -05:00
Previous versions of Hibernate determined fetches using a depth-first approach, which occasionally led
to odd "circularity" determination. Starting with 6.0, we now perform fetch determination using a width
first approach.
2021-11-30 07:35:07 -05:00
2022-01-05 17:24:11 -05:00
As back-ground, Hibernate does not always know that a fetch is truly
circular. So it uses the approach that seeing the same table and column(s) as keys might be a circularity
and stops processing fetches using that table/column(s) combination.
2021-11-24 10:25:23 -05:00
2022-01-05 17:24:11 -05:00
Given a model such as
2021-11-24 10:25:23 -05:00
```
@Entity
class Node {
@ManyToOne
2022-01-05 17:24:11 -05:00
2021-11-24 10:25:23 -05:00
Node node1;
@ManyToOne
Node node2;
}
```
2022-01-05 17:24:11 -05:00
Hibernate previously walked the graph for the `Node#node1` sub-tree prior to walking the `Node#node2` sub-tree
// todo (6.0) : clarify this some more?
2021-11-24 10:25:23 -05:00
being all eager we are executing a query with 4 joins
```
FROM Node
JOIN Node.node1
JOIN Node.node1.node2
JOIN Node.node2
JOIN Node.node2.node1
```
whereas before we
```
FROM Node
JOIN Node.node1
JOIN Node.node1.node2
```
and issue a select for `Node.node2` if the FK of `Node.node2` is not null
```
FROM Node.node2
JOIN Node.node2.node1
JOIN Node.node2.node1.node2
```
In this simple example this is not such a big deal, but if we increase the number of eager fetched self-associations
to e.g. 3 like here:
```
@Entity
class Node {
@ManyToOne
Node node1;
@ManyToOne
Node node2;
@ManyToOne
Node node3;
}
```
this results in mind-blowing 15 joins
```
FROM Node
JOIN Node.node1
JOIN Node.node1.node2
JOIN Node.node1.node2.node3
JOIN Node.node1.node3
JOIN Node.node1.node3.node2
JOIN Node.node2
JOIN Node.node2.node1
JOIN Node.node2.node1.node3
JOIN Node.node2.node3
JOIN Node.node2.node3.node1
JOIN Node.node3
JOIN Node.node3.node1
JOIN Node.node3.node1.node2
JOIN Node.node3.node2
JOIN Node.node3.node2.node1
```
as you can see, this leads to a lot of joins very quickly, but the behavior of 5.x simply was not intuitive.
To avoid creating so many joins, and also in general, we recommend that you use lazy fetching i.e. `@ManyToOne(fetch = FetchType.LAZY)`
or `@OneToOne(fetch = FetchType.LAZY)` for most associations, but this is especially important if you have multiple self-referencing associations as you can see in the example.
2021-12-06 11:12:59 -05:00
2021-12-31 17:21:32 -05:00
2022-01-05 17:24:11 -05:00
== Restructuring of `org.hibernate.loader`
2021-12-06 11:12:59 -05:00
The contents of the `loader.collection` package were restructured into `loader.ast.spi` and `loader.ast.internal`
as well as adapted to the SQM API.
The contents of `loader.custom` were adapted and moved to `query.sql`.
2021-12-31 17:21:32 -05:00
The contents of `loader.entity` and `loader.plan` were removed
2021-12-06 11:12:59 -05:00
2022-01-05 17:24:11 -05:00
== Restructuring of the sql package
2021-12-06 11:12:59 -05:00
The contents of `sql.ordering` were adapted and moved to `metamodel.mapping.ordering.ast`.
Classes of the `sql` package that were previously used for building SQL, but aren't needed anymore, were removed.
The SQL generation is now fully handled through the `SqlAstTranslator` which a `Dialect` exposes a factory for.
2022-01-05 17:24:11 -05:00
== Deprecation of hbm.xml mappings
2021-12-06 11:12:59 -05:00
2022-01-05 17:24:11 -05:00
Legacy `hbm.xml` mapping format is considered deprecated and will no longer supported beyond 6.x.
2021-11-29 19:40:02 -05:00