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
See `org.hibernate.graph.GraphParser` for details on the syntax and the
119
-
link:{userGuideBase}#fetching-strategies-dynamic-fetching-entity-graph-parsing-annotation[User Guide] for additional details.
120
-
121
-
122
-
[[session-find-multiple]]
123
-
== findMultiple() and getMultiple()
124
-
125
-
The new operations `Session.findMultiple()` and `StatelessSession.getMultiple()` provide a convenient way to fetch a batch of entities by id.
126
-
Combined with the `BatchSize` option, allows breaking up the JDBC calls into "batches".
127
-
128
-
129
-
[[operation-options]]
130
-
== FindOption, LockOption, RefreshOption
131
-
132
-
As a more typesafe replacement for hints, Jakarta Persistence now allows for "option objects" which indicate these hints. Not only is it more typesafe, but also more concise - a double win!
133
-
134
-
These "option objects" come in 3 flavors depending on what operation is being performed -
135
-
136
-
FindOption:: Used to indicate options for find operations :
137
-
* `Session.find`
138
-
* `Session.findMultiple`
139
-
* etc
140
-
LockOption:: Used to indicate options for `Session.lock`
141
-
RefreshOption:: Used to indicate options for `Session.refresh`
142
-
143
-
Each of these are interfaces. Jakarta Persistence does provide some built-in options:
144
-
145
-
CacheRetrieveMode:: Is now a `FindOption`.
146
-
CacheStoreMode:: Is now a `FindOption` and a `RefreshOption`.
147
-
LockModeType:: Is now a `FindOption` and a `RefreshOption`.
148
-
Timeout (new):: Is a `FindOption`, a `RefreshOption` and a `LockOption`. See also `org.hibernate.Timeouts` for some magic values.
149
-
PessimisticLockScope:: Is now a `FindOption`, a `RefreshOption` and a `LockOption`
150
-
151
-
Hibernate provides a few additional options:
152
-
153
-
ReadOnlyMode (new):: Is a `FindOption` which indicates whether the entities and collections being loaded should be considered read-only.
154
-
EnabledFetchProfile (new):: Is a `FindOption` indicating a fetch-profile to be enabled for the find operation.
155
-
LockMode:: Is now a `FindOption` and a `RefreshOption` (expanded version of JPA's `LockModeType`).
156
-
CacheMode:: Is now a `FindOption`.
157
-
BatchSize (new):: Is now a `FindOption`.
158
-
159
-
160
-
All operations which accept options (which previously accepted hints) accept a varargs grouping of them. E.g.
161
-
162
-
====
163
-
[source, java, indent=0]
164
-
----
165
-
Book loaded = session.find(
166
-
Book.class,
167
-
1,
168
-
LockMode.PESSIMISTIC_WRITE,
169
-
Timeouts.NO_WAIT,
170
-
new EnabledFetchProfile("with-authors")
171
-
);
172
-
----
173
-
====
174
-
175
-
176
-
[[QuerySpecification]]
177
-
== QuerySpecification, Restriction, and Range
178
-
179
-
A new API has been added for incremental definition of a query, with support for selections -
See the link:{userGuideBase}#QuerySpecification[User Guide] for details.
221
-
222
-
223
-
[[session-managed-entities]]
224
-
== Direct access to first-level cache
225
-
226
-
The new operation `Session.getManagedEntities()` allows the application to iterate over all entities in the first-level cache, or over all entities of a given type.
227
-
228
-
[NOTE]
229
-
====
230
-
This feature is considered incubating.
231
-
====
232
-
233
-
234
-
[[metamode-param-binding]]
235
-
== Use of metamodel in query parameter binding
236
-
237
-
When an argument to a query parameter is of ambiguous type, the static metamodel may now be used to disambiguate.
238
-
239
-
[source,java]
240
-
session.createSelectionQuery("from Thing where uniqueKey = ?1")
241
-
.setParameter(1, key, Thing_.uniqueKey.getType())
242
-
.getSingleResult();
243
-
244
-
245
-
[[enum-checks]]
246
-
== Converted Enums and Check Constraints
247
-
248
-
Hibernate previously added support for generating check constraints for enums mapped using `@Enumerated`
249
-
as part of schema generation. 7.0 adds the same capability for enums mapped using an `AttributeConverter`,
250
-
by asking the converter to convert all the enum constants on start up.
251
-
252
-
253
-
[[json-xml-functions]]
254
-
== JSON and XML functions
255
-
256
-
Support for most of the JSON and XML functions that the SQL standard specifies was added to HQL/Criteria.
257
-
The implementations retain the SQL standard semantics and will throw an error if emulation on a database is impossible.
258
-
259
-
New functions include:
260
-
261
-
* construction functions like `json_array()`, `json_object()`, `xmlelement()` and `xmlforest()`
262
-
* query functions like `json_value()`, `json_query()` and `xmlquery()`
263
-
* aggregation functions like `json_agg()`, `json_object_agg()` and `xmlagg()`
264
-
* manipulation functions like `json_set()`, `json_mergepatch()`
265
-
* many others
266
-
267
-
268
-
[[set-returning-functions]]
269
-
== Set-returning Functions
270
-
271
-
A set-returning function is a new type of function that can return rows and is exclusive to the `from` clause.
272
-
The concept is known in many different database SQL dialects and is sometimes referred to as table valued function or table function.
273
-
274
-
Custom set-returning functions can be registered via a `FunctionContributor`.
275
-
Out-of-the-box, some common set-returning functions are already supported or emulated
276
-
277
-
* `unnest()` - allows to turn an array into rows
278
-
* `generate_series()` - can be used to create a series of values as rows
279
-
* `json_table()` - turns a JSON document into rows
280
-
* `xmltable()` - turns an XML document into rows
281
-
282
-
283
-
[[any-discriminator]]
284
-
== @AnyDiscriminatorImplicitValues
285
-
286
-
The new `@AnyDiscriminatorImplicitValues` offers 2 related improvements for the mapping of discriminator values
287
-
for `@Any` and `ManyToAny` associations.
288
-
289
-
First, it allows control over how Hibernate determines the discriminator value to store in the database for
290
-
implicit discriminator mappings. Historically, Hibernate would always use the full name of the associated
291
-
entity.
292
-
293
-
Second, it allows mixing of explicit and implicit value strategies.
294
-
295
-
[NOTE]
296
-
====
297
-
This feature is considered incubating.
298
-
====
299
-
300
-
See the link:{userGuideBase}#associations-any[User Guide] for details.
301
-
302
-
303
-
[[stateless-session-multiple]]
304
-
== StatelessSession and Batch Operations
305
-
306
-
`StatelessSession` now supports explicit batch operations via `insertMultiple()`, `updateMultiple()`, or `deleteMultiple()`.
307
-
308
-
[NOTE]
309
-
====
310
-
This feature is considered incubating.
311
-
====
312
-
313
-
314
-
[[stateless-session-cache]]
315
-
== StatelessSession and Second Level Cache
316
-
317
-
Previously, stateless sessions never interacted with the second-level cache.
318
-
This reflected their original intended role in bulk processing.
319
-
With the advent of Jakarta Data and Hibernate Data Repositories, the responsibilities of `StatelessSession` have now expanded, and this behavior is no longer appropriate.
320
-
Thus, a stateless session now makes use of the second-level cache by default.
321
-
322
-
See the link:{migrationGuide}#stateless-session-cache[Migration Guide] for additional details.
323
-
324
-
325
-
326
-
[[stateless-session-jdbc-batching]]
327
-
== StatelessSession and JDBC Batching
328
-
329
-
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.
330
-
In Hibernate 7, the configuration property `hibernate.jdbc.batch_size` now has no effect on a stateless session.
331
-
Automatic batching may be enabled by explicitly calling `setJdbcBatchSize()`.
332
-
However, the preferred approach is to <<stateless-session-multiple,explicitly batch operations>> via `insertMultiple()`, `updateMultiple()`, or `deleteMultiple()`.
333
-
334
-
335
-
[[transaction-api]]
336
-
== Improvements to Transaction
337
-
338
-
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.
339
-
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.
340
-
341
-
[NOTE]
342
-
====
343
-
This feature is considered incubating.
344
-
====
345
-
346
-
[[collection-id-java-class]]
347
-
== @CollectionIdJavaClass
348
-
349
-
`@CollectionIdJavaClass` is an alternative to `@CollectionIdJavaType` for simpler cases of id-bag mappings. E.g.
350
-
351
-
====
352
-
[source, java, indent=0]
353
-
----
354
-
@Bag
355
-
@CollectionId(generator="increment")
356
-
@CollectionIdJavaClass(Integer.class)
357
-
Collection<Person> authors;
358
-
----
359
-
====
360
-
361
-
362
-
[[schema-manager-populate]]
363
-
== Data population
364
-
365
-
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`.
366
-
367
-
368
-
[[xml-mapping]]
369
-
== XML mappings
370
-
371
-
Hibernate's legacy `hbm.xml` mapping schema has been deprecated for quite some time, replaced by a new `mapping.xml`
372
-
schema, which is now stabilized and should be prefered.
373
-
Support for `hbm.xml` mappings will be removed in 8.0.
374
-
375
-
We offer a transformation of `hbm.xml` files into `mapping.xml` files, which is available both at build-time (Gradle plugin) and at run-time (using `hibernate.transform_hbm_xml.enabled=true`).
376
-
377
-
378
-
[[OSON-support]]
379
-
== OSON support
380
-
381
-
382
-
Starting in 21c, link:https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-oracle-database.html[Oracle JSON binary format] (also known as OSON) can now be used in Hibernate to store `JSON` data. It brings a performance boost by replacing the actual to/from String conversion.
383
-
To enable the OSON support, the link:https://github.com/oracle/ojdbc-extensions/blob/main/ojdbc-provider-jackson-oson/README.md[Oracle JDBC extension] must be added to the application classpath.
0 commit comments