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
:fn-cascase-type: footnote:cascade-type[`org.hibernate.annotations.Cascade` and `org.hibernate.annotations.CascadeType` are both fully deprecated as of 7.0]
9
10
10
11
This guide discusses migration to Hibernate ORM version 7.0. For migration from
@@ -44,10 +45,15 @@ This required a few actions on our part:
44
45
[[requirements]]
45
46
== Requirements
46
47
47
-
* Java 17, or greater
48
+
* <<java-17>>, or greater
48
49
* <<jpa-32>>
49
50
* <<hibernate-models>>
50
51
52
+
[[java-17]]
53
+
=== Java 17
54
+
55
+
Hibernate now baselines on Java 17. Newer Java versions may also be used.
56
+
51
57
52
58
[[jpa-32]]
53
59
=== Jakarta Persistence 3.2
@@ -70,6 +76,9 @@ This required a few actions on our part:
70
76
71
77
See this https://in.relation.to/2024/04/01/jakarta-persistence-3/[blog post] for a good discussion of the changes in Jakarta Persistence 3.2.
72
78
79
+
- https://ci.hibernate.org/view/ORM/job/hibernate-orm-tck-3.2/job/wip%252F7.0/24/[TCK Results] with Java 17
80
+
- https://ci.hibernate.org/view/ORM/job/hibernate-orm-tck-3.2/job/wip%252F7.0/25/[TCK Results] with Java 21
81
+
73
82
[[hibernate-models]]
74
83
=== Hibernate Models
75
84
@@ -94,144 +103,8 @@ annotations. Check out its project page for complete details.
94
103
[[new-features]]
95
104
== New Features
96
105
97
-
New features introduced in 7.0...
98
-
99
-
[[soft-delete-timestamp]]
100
-
=== @SoftDelete with TIMESTAMP
101
-
102
-
Soft-delete now supports the strategy of tracking the timestamp at which the soft-delete occurred,
103
-
in addition to the previous truth-based strategies.
104
-
See the link:{user-guide-url}#soft-delete[User Guide] for details.
105
-
106
-
107
-
[[embedded-column-naming]]
108
-
=== @EmbeddedColumnNaming
109
-
110
-
A long-requested feature for both Hibernate and Jakarta Persistence has been the ability to
111
-
define a prefix for the names of columns associated with an embedded value.
112
-
113
-
7.0 adds support for this using the new `@EmbeddedColumnNaming` annotation. The annotation
114
-
accepts a format pattern, so is a little more flexible than just a prefix.
115
-
116
-
Consider a typical `Person` / `Address` composition:
117
-
118
-
[source,java]
119
-
----
120
-
@Embeddable
121
-
class Address {
122
-
String street;
123
-
String city;
124
-
...
125
-
}
126
-
127
-
@Entity
128
-
class Person {
129
-
...
130
-
131
-
@Embedded
132
-
@EmbeddedColumnNaming("home_%")
133
-
Address homeAddress;
134
-
135
-
@Embedded
136
-
@EmbeddedColumnNaming("work_%")
137
-
Address workAddress;
138
-
139
-
}
140
-
----
141
-
142
-
This instructs Hibernate to use the column names `home_street`, `home_city`, `work_street`, and so on.
143
-
144
-
See the link:{user-guide-url}#embeddable-column-naming[User Guide] for details.
145
-
146
-
[[NamedEntityGraph]]
147
-
=== @NamedEntityGraph
148
-
149
-
A new annotation (`@org.hibernate.annotations.NamedEntityGraph`) has been added to allow
150
-
specifying a named entity-graph using Hibernate's ability to parse a string representation of the graph.
See `org.hibernate.graph.GraphParser` for details on the syntax and the
164
-
link:{user-guide-url}#fetching-strategies-dynamic-fetching-entity-graph-parsing-annotation[User Guide] for additional details.
165
-
166
-
167
-
[[enum-checks]]
168
-
=== Converted Enums and Check Constraints
169
-
170
-
Hibernate previously added support for generating check constraints for enums mapped using `@Enumerated`
171
-
as part of schema generation. 7.0 adds the same capability for enums mapped using an `AttributeConverter`,
172
-
by asking the converter to convert all the enum constants on start up.
173
-
174
-
[[hbm-transform]]
175
-
=== hbm.xml Transformation
176
-
177
-
Hibernate's legacy `hbm.xml` mapping schema has been deprecated for quite some time, replaced by a new `mapping.xml`
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
-
180
-
This tool is available as both:
181
-
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
-
185
-
Build-time transformation is preferred.
186
-
187
-
[NOTE]
188
-
====
189
-
Initial versions of the transformation processed one file at a time.
190
-
This is now done across the entire set of `hbm.xml` files at once.
191
-
While most users will never see this change, it might impact integrations which tie-in to XML processing.
192
-
====
193
-
194
-
[[stateless-session-cache]]
195
-
=== StatelessSession and Second Level Cache
196
-
197
-
Previously, stateless sessions never interacted with the second-level cache.
198
-
This reflected their original intended role in bulk processing.
199
-
With the advent of Jakarta Data and Hibernate Data Repositories, the responsibilities of `StatelessSession` have now expanded, and this behavior is no longer appropriate.
200
-
201
-
Thus, a stateless session now makes use of the second-level cache by default.
202
-
To completely bypass the second-level cache, recovering the previous behavior, call `setCacheMode(CacheMode.IGNORE)`.
203
-
204
-
It's often important to explicitly disable puts to the second-level cache in code which performs bulk processing.
205
-
Set the cache mode to `GET` or configure `jakarta.persistence.cache.storeMode` to `BYPASS`.
206
-
207
-
[[stateless-session-jdbc-batching]]
208
-
=== StatelessSession and JDBC Batching
209
-
210
-
Automatic JDBC batching has the side effect of delaying the execution of the batched operation, and this undermines the synchronous nature of operations performed through a stateless session.
211
-
In Hibernate 7, the configuration property `hibernate.jdbc.batch_size` now has no effect on a stateless session.
212
-
Automatic batching may be enabled by explicitly calling `setJdbcBatchSize()`.
213
-
However, the preferred approach is to explicitly batch operations via `insertMultiple()`, `updateMultiple()`, or `deleteMultiple()`.
106
+
See the link:{releaseSeriesBase}#whats-new[website] for the list of new features in the 7.0 series.
214
107
215
-
[[session-find-multiple]]
216
-
=== findMultiple()
217
-
218
-
The new operation `Session.findMultiple()`, along with the `BatchSize` option provides a convenient way to fetch a batch of entities by id.
219
-
220
-
[[session-managed-entities]]
221
-
=== Direct access to first-level cache
222
-
223
-
The new operation `Session.getManagedEntities()` allows the application program to iterate over all entities in the first-level cache, or over all entities of a given type.
224
-
225
-
[[schema-manager-populate]]
226
-
=== Data population
227
-
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
-
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
108
236
109
237
110
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -241,21 +114,27 @@ New operations were added to the `Transaction` interface, allowing code to inspe
241
114
[[api-changes]]
242
115
== Changes to API
243
116
117
+
This section describes changes to contracts (classes, interfaces, methods, etc.) which are consider https://hibernate.org/community/compatibility-policy/#api[API].
118
+
119
+
[[defer-to-jpa]]
120
+
=== Defer to JPA
121
+
244
122
A general theme in 7.0 has been to remove Hibernate-specific features that have a direct replacement in JPA.
245
123
246
124
[[session-load]]
247
-
=== Session#load
125
+
==== Session#load
248
126
249
127
`Session#load` methods have been removed in favor of `Session#getReference` which have the same semantic.
250
128
129
+
251
130
[[session-get]]
252
-
=== Session#get
131
+
==== Session#get
253
132
`Session#get` methods were deprecated in favor of the JPA-standard `Session#find`, and new overloads of `Session#find` were added.
254
133
255
134
NOTE: `Session#get` was not previously deprecated as `Session#load` was, so it was not appropriate to remove it.
256
135
257
136
[[session-refresh]]
258
-
=== Session#refresh
137
+
==== Session#refresh
259
138
260
139
The forms of `Session#refresh` accepting an entity-name have been removed; the passed entity already indicates the entity-name (even with dynamic models).
261
140
@@ -265,7 +144,7 @@ The forms of `Session#refresh` accepting an entity-name have been removed; the p
265
144
Removed in favor of `Session#refresh(Object object, LockOptions lockOptions)`
All forms of `Session#save`, `Session#update`, `Session#saveOrUpdate` have been removed. See the discussion at <<flush-persist>>.
271
150
@@ -280,7 +159,7 @@ Relatedly, `org.hibernate.annotations.CascadeType#SAVE_UPDATE` has been removed
280
159
281
160
282
161
[[session-delete]]
283
-
=== Session#delete
162
+
==== Session#delete
284
163
285
164
`Session#delete` methods has been removed in favor of `Session#remove`. Relatedly, `org.hibernate.annotations.CascadeType#DELETE` was removed in favor of `org.hibernate.annotations.CascadeType#REMOVE`{fn-cascase-type}
286
165
@@ -346,13 +225,6 @@ All such cases though are already controllable by the application.
346
225
347
226
The effect can also often be mitigated using Hibernate's bytecode-based laziness (possibly combined with `@ConcreteProxy`).
348
227
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
-
356
228
357
229
[[misc-api]]
358
230
=== Miscellaneous
@@ -373,6 +245,8 @@ The solution was to change the signature of `nullSafeSet()` and `nullSafeGet()`
373
245
[[spi-changes]]
374
246
== Changes to SPI
375
247
248
+
This section describes changes to contracts (classes, interfaces, methods, etc.) which are consider https://hibernate.org/community/compatibility-policy/#spi[SPI].
249
+
376
250
[[configurable-generators]]
377
251
=== Configurable generators
378
252
@@ -401,13 +275,12 @@ Quite a few (again, previously deprecated) methods on `Interceptor` have been re
401
275
Additionally, `EmptyInterceptor` was removed. As `org.hibernate.Interceptor` now uses default methods, one can simply implement `Interceptor` to the same end.
was removed in favor of `org.hibernate.metamodel.MappingMetmodel` or `org.hibernate.metamodel.model.domain.JpaMetamodel`
409
-
* Removed `AdditionalJaxbMappingProducer` in favor of `AdditionalMappingContributor`.
410
-
* Removed `MetadataContributor` in favor of `AdditionalMappingContributor`
281
+
The API interfaces `UserType` and `CompositeUserType` leaked the SPI types `SharedSessionContractImplementor` and `SessionFactoryImplementor`, which was a layer-breaker.
282
+
283
+
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`.
411
284
412
285
[[jfr-spi]]
413
286
=== JFR SPI
@@ -416,6 +289,15 @@ The types `EventMonitor` and `DiagonosticEvent` replace the now-deprecated SPIs
416
289
417
290
Hibernate now reports many more kinds of `DiagnosticEvent` to JFR.
was removed in favor of `org.hibernate.metamodel.MappingMetmodel` or `org.hibernate.metamodel.model.domain.JpaMetamodel`
297
+
* Removed `AdditionalJaxbMappingProducer` in favor of `AdditionalMappingContributor`.
298
+
* Removed `MetadataContributor` in favor of `AdditionalMappingContributor`
299
+
300
+
419
301
420
302
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
421
303
// Changes in Behavior
@@ -424,6 +306,7 @@ Hibernate now reports many more kinds of `DiagnosticEvent` to JFR.
424
306
[[behavior-changes]]
425
307
== Changes in Behavior
426
308
309
+
427
310
[[model-validation]]
428
311
=== Domain Model Validations
429
312
@@ -506,6 +389,29 @@ This includes auto-applied converters.
506
389
To suppress the error for an auto-applied converter, use `@Convert(disableConversion=true)`.
507
390
508
391
392
+
[[stateless-session-behavior]]
393
+
=== StatelessSession Behavior
394
+
395
+
The behavior of Hibernate's `StatelessSession` has changed in 2 specific ways to be aware of:
396
+
397
+
[[stateless-session-cache]]
398
+
==== StatelessSession and Second-Level Cache
399
+
400
+
A stateless session now link:{releaseSeriesBase}#stateless-session-cache[makes use of the second-level cache] by default. This will affect migrating applications using second-level cache and `StatelessSession`.
401
+
402
+
To completely bypass the second-level cache, recovering the previous behavior, call `setCacheMode(CacheMode.IGNORE)`.
403
+
404
+
It's often important to explicitly disable puts to the second-level cache in code which performs bulk processing.
405
+
Set the cache mode to `GET` or configure `jakarta.persistence.cache.storeMode` to `BYPASS`.
406
+
407
+
408
+
[[stateless-session-jdbc-batching]]
409
+
==== StatelessSession and JDBC Batching
410
+
411
+
The configuration property `hibernate.jdbc.batch_size` now has link:{releaseSeriesBase}#stateless-session-jdbc-batching[no effect on a StatelessSession].
412
+
JDBC batching may be enabled by explicitly calling `setJdbcBatchSize()`.
413
+
However, the preferred approach is to use the new link:{releaseSeriesBase}#stateless-session-multiple[explicit batch operations] via `insertMultiple()`, `updateMultiple()`, or `deleteMultiple()`.
414
+
509
415
510
416
[[create-query]]
511
417
=== Query with Implicit SELECT and No Explicit Result Type
@@ -521,7 +427,7 @@ or:
521
427
522
428
[source,java]
523
429
List query =
524
-
session.createQuery("from X join ys")
430
+
session.createQuery("from X join y")
525
431
.getResultList()
526
432
527
433
The select list was inferred based on the `from` clause.
@@ -550,12 +456,13 @@ or:
550
456
551
457
[source,java]
552
458
List<X> result =
553
-
session.createQuery("from X join ys", X.class)
459
+
session.createQuery("from X join y", X.class)
554
460
.getResultList()
555
461
556
462
[[flush-persist]]
557
463
=== Session flush and persist
558
464
465
+
559
466
The removal of `CascadeType.SAVE_UPDATE` slightly changes the persist and flush behaviour to conform with the Jakarta Persistence specification.
560
467
561
468
Making a transient entity persistent or flushing a managed entity now results in an `jakarta.persistence.EntityExistsException` if:
@@ -710,6 +617,8 @@ Starting in 7.0, when `ValidationMode#AUTO` is specified and a Bean Validation p
710
617
[[ddl-changes]]
711
618
== Changes Affecting DDL
712
619
620
+
This section describes changes which may affect the application's database schema.
621
+
713
622
[[ddl-implicit-datatype-timestamp]]
714
623
=== Default Precision for timestamp
715
624
@@ -762,9 +671,7 @@ Now, `varchar(1)` is used by default.
762
671
[[pools]]
763
672
== Connection Pools
764
673
765
-
Since Vibur and Proxool are no longer actively developed, support for these connection pools was removed.
766
-
767
-
As part of the effort to relicense Hibernate, it also became necessary to drop support for Oracle UCP connection pool.
674
+
We have decided to drop built-in support for the Vibur, Proxool and UCP Connection Pools for a variety of reasons - the main one being that we are not able to properly test them.
768
675
769
676
We recommend using https://github.com/agroal/agroal[Agroal] or https://github.com/brettwooldridge/HikariCP[HikariCP] instead.
770
677
Alternatively, you may implement the `ConnectionProvider` interface to integrate the connection pool of your choice.
0 commit comments