You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: migration-guide.adoc
+51-19
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ This required a few actions on our part:
56
56
57
57
* Type parameters:
58
58
** 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.
60
60
* New JPA features colliding with previous Hibernate extension features:
61
61
** `Nulls` (JPA) v. `NullPrecedence` (Hibernate), including JPA's new `Order#getNullPrecedence()` returning `Nulls`
62
62
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.
107
107
[[embedded-column-naming]]
108
108
=== @EmbeddedColumnNaming
109
109
110
-
A longrequested 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
111
111
define a prefix for the names of columns associated with an embedded value.
112
112
113
113
7.0 adds support for this using the new `@EmbeddedColumnNaming` annotation. The annotation
114
114
accepts a format pattern, so is a little more flexible than just a prefix.
115
115
116
-
Consider a typical Person / Address composition:
116
+
Consider a typical `Person` / `Address` composition:
117
117
118
118
[source,java]
119
119
----
@@ -139,7 +139,7 @@ class Person {
139
139
}
140
140
----
141
141
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.
143
143
144
144
See the link:{user-guide-url}#embeddable-column-naming[User Guide] for details.
145
145
@@ -177,10 +177,10 @@ by asking the converter to convert all the enum constants on start up.
177
177
Hibernate's legacy `hbm.xml` mapping schema has been deprecated for quite some time, replaced by a new `mapping.xml`
178
178
schema. In 7.0, this `mapping.xml` is stabilized and we now offer a transformation of `hbm.xml` files into `mapping.xml` files.
179
179
180
-
This tool is available as both -
180
+
This tool is available as both:
181
181
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`
184
184
185
185
Build-time transformation is preferred.
186
186
@@ -227,6 +227,12 @@ The new operation `Session.getManagedEntities()` allows the application program
227
227
228
228
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`.
229
229
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
+
230
236
231
237
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232
238
// API changes
@@ -242,7 +248,11 @@ A general theme in 7.0 has been to remove Hibernate-specific features that have
242
248
243
249
`Session#load` methods have been removed in favor of `Session#getReference` which have the same semantic.
244
250
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.
246
256
247
257
[[session-refresh]]
248
258
=== Session#refresh
@@ -336,6 +346,13 @@ All such cases though are already controllable by the application.
336
346
337
347
The effect can also often be mitigated using Hibernate's bytecode-based laziness (possibly combined with `@ConcreteProxy`).
338
348
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
+
339
356
340
357
[[misc-api]]
341
358
=== Miscellaneous
@@ -344,6 +361,8 @@ The effect can also often be mitigated using Hibernate's bytecode-based laziness
344
361
* Removed `SqmQualifiedJoin` - all joins are qualified.
345
362
* Both `NaturalIdLoadAccess#using(Map)` and `NaturalIdMultiLoadAccess#compoundValue()` have been removed in favor of `Map#of()`
346
363
* 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`
347
366
348
367
349
368
@@ -390,6 +409,12 @@ was removed in favor of `org.hibernate.metamodel.MappingMetmodel` or `org.hibern
390
409
* Removed `AdditionalJaxbMappingProducer` in favor of `AdditionalMappingContributor`.
391
410
* Removed `MetadataContributor` in favor of `AdditionalMappingContributor`
392
411
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.
393
418
394
419
395
420
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -496,17 +521,18 @@ or:
496
521
497
522
[source,java]
498
523
List query =
499
-
session.createQuery("from X join y")
524
+
session.createQuery("from X join ys")
500
525
.getResultList()
501
526
502
527
The select list was inferred based on the `from` clause.
503
528
504
529
In Hibernate 6 we decided to deprecate this overload of `createQuery()`, since:
505
530
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
507
533
- the second query is truly ambiguous, with no obviously intuitive interpretation.
508
534
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_.
510
536
Migration paths include:
511
537
512
538
1. explicitly specify the `select` list,
@@ -524,17 +550,21 @@ or:
524
550
525
551
[source,java]
526
552
List<X> result =
527
-
session.createQuery("from X join y", X.class)
553
+
session.createQuery("from X join ys", X.class)
528
554
.getResultList()
529
555
530
556
[[flush-persist]]
531
557
=== Session flush and persist
532
558
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:
534
562
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.
536
565
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.
538
568
539
569
Consider the following model
540
570
@@ -567,7 +597,7 @@ Assuming we have `c1` as a detached `Child`, the following code will now result
@@ -734,7 +764,9 @@ Now, `varchar(1)` is used by default.
734
764
735
765
Since Vibur and Proxool are no longer actively developed, support for these connection pools was removed.
736
766
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.
738
768
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`.
0 commit comments