Skip to content

Commit dc20229

Browse files
committed
improvements to the migration guide
1 parent d2e67cd commit dc20229

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

migration-guide.adoc

+51-19
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ This required a few actions on our part:
5656

5757
* Type parameters:
5858
** Affects much of the Criteria API - especially roots, joins, paths
59-
** Affects much of the Graph API - see <<load-fetch-graphs>> for details.
59+
** Affects much of the Entity Graph API - see <<load-fetch-graphs>> for details.
6060
* New JPA features colliding with previous Hibernate extension features:
6161
** `Nulls` (JPA) v. `NullPrecedence` (Hibernate), including JPA's new `Order#getNullPrecedence()` returning `Nulls`
6262
colliding with Hibernate's `SqmSortSpecification#getNullPrecedence` returning `NullPrecedence`. Hibernate's form
@@ -107,13 +107,13 @@ See the link:{user-guide-url}#soft-delete[User Guide] for details.
107107
[[embedded-column-naming]]
108108
=== @EmbeddedColumnNaming
109109

110-
A long requested feature for both Hibernate and Jakarta Persistence has been the ability to
110+
A long-requested feature for both Hibernate and Jakarta Persistence has been the ability to
111111
define a prefix for the names of columns associated with an embedded value.
112112

113113
7.0 adds support for this using the new `@EmbeddedColumnNaming` annotation. The annotation
114114
accepts a format pattern, so is a little more flexible than just a prefix.
115115

116-
Consider a typical Person / Address composition:
116+
Consider a typical `Person` / `Address` composition:
117117

118118
[source,java]
119119
----
@@ -139,7 +139,7 @@ class Person {
139139
}
140140
----
141141

142-
This triggers Hibernate to use the column names `home_street`, `home_city`, `work_street`, ...
142+
This instructs Hibernate to use the column names `home_street`, `home_city`, `work_street`, and so on.
143143

144144
See the link:{user-guide-url}#embeddable-column-naming[User Guide] for details.
145145

@@ -177,10 +177,10 @@ by asking the converter to convert all the enum constants on start up.
177177
Hibernate's legacy `hbm.xml` mapping schema has been deprecated for quite some time, replaced by a new `mapping.xml`
178178
schema. In 7.0, this `mapping.xml` is stabilized and we now offer a transformation of `hbm.xml` files into `mapping.xml` files.
179179

180-
This tool is available as both -
180+
This tool is available as both:
181181

182-
* build-time transformation (currently only offered as a Gradle plugin)
183-
* run-time transformation, using `hibernate.transform_hbm_xml.enabled=true`
182+
* a build-time transformation (currently only offered as a Gradle plugin), or
183+
* a runtime transformation, using `hibernate.transform_hbm_xml.enabled=true`
184184

185185
Build-time transformation is preferred.
186186

@@ -227,6 +227,12 @@ The new operation `Session.getManagedEntities()` allows the application program
227227

228228
Setting `jakarta.persistence.schema-generation.database.action=populate` or calling `SchemaManager.populate()` populates an existing schema with initial data in `/import.sql` or other SQL scripts specified via `jakarta.persistence.sql-load-script-source`.
229229

230+
[[transaction-api]]
231+
=== Improvements to Transaction
232+
233+
The `Transaction` interface leaks the SPI type `TransactionStatus` via `getStatus()`, and the JTA-defined type `Synchronization` via `registerSynchronization()`, which breaks layering in a fairly harmless way.
234+
New operations were added to the `Transaction` interface, allowing code to inspect the status of the transaction or register callbacks without the use of layer-breaking operations.
235+
230236

231237
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232238
// API changes
@@ -242,7 +248,11 @@ A general theme in 7.0 has been to remove Hibernate-specific features that have
242248

243249
`Session#load` methods have been removed in favor of `Session#getReference` which have the same semantic.
244250

245-
NOTE: `Session#get` was not previously deprecated as `Session#load` was, so it was not appropriate to remove. Starting in 7.0, `Session#get` is considered deprecated, to be removed in 8.0. Per the deprecation notes, use `Session#find` instead.
251+
[[session-get]]
252+
=== Session#get
253+
`Session#get` methods were deprecated in favor of the JPA-standard `Session#find`, and new overloads of `Session#find` were added.
254+
255+
NOTE: `Session#get` was not previously deprecated as `Session#load` was, so it was not appropriate to remove it.
246256

247257
[[session-refresh]]
248258
=== Session#refresh
@@ -336,6 +346,13 @@ All such cases though are already controllable by the application.
336346

337347
The effect can also often be mitigated using Hibernate's bytecode-based laziness (possibly combined with `@ConcreteProxy`).
338348

349+
[[usertype]]
350+
=== Changes to UserType and CompositeUserType
351+
352+
The API interfaces `UserType` and `CompositeUserType` leaked the SPI types `SharedSessionContractImplementor` and `SessionFactoryImplementor`, which was a layer-breaker.
353+
354+
The solution was to change the signature of `nullSafeSet()` and `nullSafeGet()` in `UserType` via deprecation of the previous declarations, and remove some unnecessary parameters from methods of the incubating interface `CompositeUserType`.
355+
339356

340357
[[misc-api]]
341358
=== Miscellaneous
@@ -344,6 +361,8 @@ The effect can also often be mitigated using Hibernate's bytecode-based laziness
344361
* Removed `SqmQualifiedJoin` - all joins are qualified.
345362
* Both `NaturalIdLoadAccess#using(Map)` and `NaturalIdMultiLoadAccess#compoundValue()` have been removed in favor of `Map#of()`
346363
* Removed `Session.LockRequest` - use `LockOptions` instead
364+
* `SessionFactory.createEntityManager()` now returns `Session` for convenience
365+
* `CommonQueryContract.setFlushMode()` was deprecated in favor of `setQueryFlushMode` accepting a `QueryFlushMode`
347366

348367

349368

@@ -390,6 +409,12 @@ was removed in favor of `org.hibernate.metamodel.MappingMetmodel` or `org.hibern
390409
* Removed `AdditionalJaxbMappingProducer` in favor of `AdditionalMappingContributor`.
391410
* Removed `MetadataContributor` in favor of `AdditionalMappingContributor`
392411

412+
[[jfr-spi]]
413+
=== JFR SPI
414+
415+
The types `EventMonitor` and `DiagonosticEvent` replace the now-deprecated SPIs `EventManager` and `HibernateMonitoringEvent` use for integration with Java Flight Recorder.
416+
417+
Hibernate now reports many more kinds of `DiagnosticEvent` to JFR.
393418

394419

395420
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -496,17 +521,18 @@ or:
496521

497522
[source,java]
498523
List query =
499-
session.createQuery("from X join y")
524+
session.createQuery("from X join ys")
500525
.getResultList()
501526

502527
The select list was inferred based on the `from` clause.
503528

504529
In Hibernate 6 we decided to deprecate this overload of `createQuery()`, since:
505530

506-
- it returns a raw type, resulting in compiler warnings in client code, and
531+
- it returns a raw type `Query`, resulting in compiler warnings in client code,
532+
- each query result must be explicitly cast from `Object` to the query result type, and
507533
- the second query is truly ambiguous, with no obviously intuitive interpretation.
508534

509-
As of Hibernate 7, the method is remains deprecated, and potentially-ambiguous queries _are no longer accepted_.
535+
As of Hibernate 7, the method remains deprecated, and potentially-ambiguous queries _are no longer accepted_.
510536
Migration paths include:
511537

512538
1. explicitly specify the `select` list,
@@ -524,17 +550,21 @@ or:
524550

525551
[source,java]
526552
List<X> result =
527-
session.createQuery("from X join y", X.class)
553+
session.createQuery("from X join ys", X.class)
528554
.getResultList()
529555

530556
[[flush-persist]]
531557
=== Session flush and persist
532558

533-
The removal of `CascadeType.SAVE_UPDATE` slightly changes the persist and flush behaviour to conform with Jakarta Persistence.
559+
The removal of `CascadeType.SAVE_UPDATE` slightly changes the persist and flush behaviour to conform with the Jakarta Persistence specification.
560+
561+
Making a transient entity persistent or flushing a managed entity now results in an `jakarta.persistence.EntityExistsException` if:
534562

535-
Persisting a transient entity or flushing a manged entity with an associated detached entity having the association annotated with `cascade = CascadeType.ALL` or `cascade = CascadeType.PERSIST` throws now an `jakarta.persistence.EntityExistsException` if the detached entity has not been re-associated with the Session.
563+
- the entity has an association with `cascade = CascadeType.ALL` or `cascade = CascadeType.PERSIST`, and
564+
- the association references a detached instance of the associated entity class.
536565

537-
To re-associate the detached entity with the Session the `Session#merge` method can be used.
566+
To avoid this exception, the reference to the detached instance should be replaced with a reference to a managed instance associated with the current session.
567+
Such a reference may be obtained by calling `merge()` or `getReference()` on the detached entity instance.
538568

539569
Consider the following model
540570

@@ -567,7 +597,7 @@ Assuming we have `c1` as a detached `Child`, the following code will now result
567597

568598
[source,java]
569599
----
570-
Parent parent = session.get( Parent.class, parentId );
600+
Parent parent = session.find( Parent.class, parentId );
571601
parent.addChild( c1 );
572602
----
573603

@@ -576,7 +606,7 @@ Instead, `c1` must first be re-associated with the Session using merge:
576606

577607
[source,java]
578608
----
579-
Parent parent = session.get( Parent.class, parentId );
609+
Parent parent = session.find( Parent.class, parentId );
580610
Child merged = session.merge( c1 );
581611
parent.addChild( merged );
582612
----
@@ -734,7 +764,9 @@ Now, `varchar(1)` is used by default.
734764

735765
Since Vibur and Proxool are no longer actively developed, support for these connection pools was removed.
736766

737-
As part of the effort to relicense, it also became necessary to drop support for UCP connection pool.
767+
As part of the effort to relicense Hibernate, it also became necessary to drop support for Oracle UCP connection pool.
738768

739-
We recommend using Agroal or HikariCP instead; or implement the `ConnectionProvider` yourself to integrate with the Connection Pool of your choice (in fact other Connection Pools are known to ship implementations of the Hibernate `ConnectionProvider` already).
769+
We recommend using https://github.com/agroal/agroal[Agroal] or https://github.com/brettwooldridge/HikariCP[HikariCP] instead.
770+
Alternatively, you may implement the `ConnectionProvider` interface to integrate the connection pool of your choice.
771+
In fact, some connection pools already include their own implementations of `ConnectionProvider`.
740772

0 commit comments

Comments
 (0)