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,138 +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 triggers Hibernate to use the column names `home_street`, `home_city`, `work_street`, ...
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
106
+
See the link:{releaseSeriesBase}#whats-new[website] for the list of new features in the 7.0 series.
176
107
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
-
* build-time transformation (currently only offered as a Gradle plugin)
183
-
* run-time 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()`.
214
-
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
108
230
109
231
110
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -235,17 +114,22 @@ Setting `jakarta.persistence.schema-generation.database.action=populate` or call
235
114
[[api-changes]]
236
115
== Changes to API
237
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
+
238
122
A general theme in 7.0 has been to remove Hibernate-specific features that have a direct replacement in JPA.
239
123
240
124
[[session-load]]
241
-
=== Session#load
125
+
==== Session#load
242
126
243
127
`Session#load` methods have been removed in favor of `Session#getReference` which have the same semantic.
244
128
245
129
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.
246
130
247
131
[[session-refresh]]
248
-
=== Session#refresh
132
+
==== Session#refresh
249
133
250
134
The forms of `Session#refresh` accepting an entity-name have been removed; the passed entity already indicates the entity-name (even with dynamic models).
251
135
@@ -255,7 +139,7 @@ The forms of `Session#refresh` accepting an entity-name have been removed; the p
255
139
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>>.
261
145
@@ -270,7 +154,7 @@ Relatedly, `org.hibernate.annotations.CascadeType#SAVE_UPDATE` has been removed
270
154
271
155
272
156
[[session-delete]]
273
-
=== Session#delete
157
+
==== Session#delete
274
158
275
159
`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}
276
160
@@ -354,6 +238,8 @@ The effect can also often be mitigated using Hibernate's bytecode-based laziness
354
238
[[spi-changes]]
355
239
== Changes to SPI
356
240
241
+
This section describes changes to contracts (classes, interfaces, methods, etc.) which are consider https://hibernate.org/community/compatibility-policy/#spi[SPI].
242
+
357
243
[[configurable-generators]]
358
244
=== Configurable generators
359
245
@@ -399,6 +285,7 @@ was removed in favor of `org.hibernate.metamodel.MappingMetmodel` or `org.hibern
399
285
[[behavior-changes]]
400
286
== Changes in Behavior
401
287
288
+
402
289
[[model-validation]]
403
290
=== Domain Model Validations
404
291
@@ -481,6 +368,29 @@ This includes auto-applied converters.
481
368
To suppress the error for an auto-applied converter, use `@Convert(disableConversion=true)`.
482
369
483
370
371
+
[[stateless-session-behavior]]
372
+
=== StatelessSession Behavior
373
+
374
+
The behavior of Hibernate's `StatelessSession` has changed in 2 specific ways to be aware of:
375
+
376
+
[[stateless-session-cache]]
377
+
==== StatelessSession and Second-Level Cache
378
+
379
+
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`.
380
+
381
+
To completely bypass the second-level cache, recovering the previous behavior, call `setCacheMode(CacheMode.IGNORE)`.
382
+
383
+
It's often important to explicitly disable puts to the second-level cache in code which performs bulk processing.
384
+
Set the cache mode to `GET` or configure `jakarta.persistence.cache.storeMode` to `BYPASS`.
385
+
386
+
387
+
[[stateless-session-jdbc-batching]]
388
+
==== StatelessSession and JDBC Batching
389
+
390
+
The configuration property `hibernate.jdbc.batch_size` now has link:{releaseSeriesBase}#stateless-session-jdbc-batching[no effect on a StatelessSession].
391
+
JDBC batching may be enabled by explicitly calling `setJdbcBatchSize()`.
392
+
However, the preferred approach is to use the new link:{releaseSeriesBase}#stateless-session-multiple[explicit batch operations] via `insertMultiple()`, `updateMultiple()`, or `deleteMultiple()`.
393
+
484
394
485
395
[[create-query]]
486
396
=== Query with Implicit SELECT and No Explicit Result Type
@@ -680,6 +590,8 @@ Starting in 7.0, when `ValidationMode#AUTO` is specified and a Bean Validation p
680
590
[[ddl-changes]]
681
591
== Changes Affecting DDL
682
592
593
+
This section describes changes which may affect the application's database schema.
594
+
683
595
[[ddl-implicit-datatype-timestamp]]
684
596
=== Default Precision for timestamp
685
597
@@ -732,9 +644,7 @@ Now, `varchar(1)` is used by default.
732
644
[[pools]]
733
645
== Connection Pools
734
646
735
-
Since Vibur and Proxool are no longer actively developed, support for these connection pools was removed.
736
-
737
-
As part of the effort to relicense, it also became necessary to drop support for UCP connection pool.
647
+
We have decided to drop built-in support for the Vibur, Proxool and UCP Connection Pools. This is dues to a variety of reasons, a main one being that we are not able to properly test them.
738
648
739
649
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).
7.0 migrates from [Hibernate Commons Annotations](https://github.com/hibernate/hibernate-commons-annotations/) (HCANN) to the new [Hibernate Models](https://github.com/hibernate/hibernate-models) project for low-level processing of an application domain model, reading annotations and weaving in XML mapping documents.
40
-
See the [Migration Guide](https://docs.jboss.org/hibernate/orm/7.0/migration-guide/migration-guide.html#hibernate-models) for details.
41
-
42
-
43
-
### <aname="json-and-xml-functions"></a> JSON and XML functions
44
-
45
-
Support for most of the JSON and XML functions that the SQL standard specifies was added to HQL/Criteria.
46
-
The implementations retain the SQL standard semantics and will throw an error if emulation on a database is impossible.
47
-
48
-
New functions include:
49
-
50
-
* construction functions like `json_array()`, `json_object()`, `xmlelement()` and `xmlforest()`
51
-
* query functions like `json_value()`, `json_query()` and `xmlquery()`
52
-
* aggregation functions like `json_agg()`, `json_object_agg()` and `xmlagg()`
53
-
* manipulation functions like `json_set()`, `json_mergepatch()`
54
-
* any many more
55
-
56
-
> The functions are incubating/tech-preview - to use them in HQL it is necessary to enable the `hibernate.query.hql.json_functions_enabled` and `hibernate.query.hql.xml_functions_enabled` configuration settings.
The new `@AnyDiscriminatorImplicitValues` offers 2 related improvements for the mapping of discriminator values
75
-
for `@Any` and `ManyToAny` associations.
76
-
77
-
First, it allows control over how Hibernate determines the discriminator value to store in the database for
78
-
implicit discriminator mappings. Historically, Hibernate would always use the full name of the associated
79
-
entity.
80
-
81
-
Second, it allows mixing of explicit and implicit value strategies.
82
-
83
-
See the [Migration Guide](https://docs.jboss.org/hibernate/orm/7.0/userguide/html_single/Hibernate_User_Guide.html#associations-any) for details.
84
-
85
-
### <a name=cleanup"></a> Clean-up
86
-
87
-
A lot of deprecated contracts and behavior has been removed.
88
-
See the [Migration Guide](https://docs.jboss.org/hibernate/orm/7.0/migration-guide/migration-guide.html#cleanup) for details.
89
-
2
+
* See the [website](https://hibernate.org.orm/releases/7.0) for requirements and new features in 7.0.
3
+
* See the [Migration Guide](https://docs.jboss.org/hibernate/orm/7.0/migration-guide/migration-guide.html) for details about migration from version 6.6 to 7.0.
0 commit comments