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: documentation/src/main/asciidoc/introduction/Interacting.adoc
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -383,7 +383,7 @@ It's not necessary to dirty-check on entity instance in read-only mode.
383
383
384
384
Hibernate features three complementary ways to write queries:
385
385
386
-
- the _Hibernate Query Language_, an extremely powerful superset of JPQL, which abstracts most of the features of modern SQL queries,
386
+
- the _Hibernate Query Language_, an extremely powerful superset of JPQL, which abstracts most of the features of modern dialects of SQL,
387
387
- the JPA _criteria query_ API, along with extensions, allowing almost any HQL query to be constructed programmatically via a typesafe API, and, of course
388
388
- for when all else fails, _native SQL_ queries.
389
389
@@ -393,7 +393,7 @@ Hibernate features three complementary ways to write queries:
A full discussion of the query language would require just as much text as the rest of this Introduction.
396
-
Fortunately, HQL is already described in exhaustive detail in the {hql}[User Guide].
396
+
Fortunately, HQL is already described in exhaustive (and exhausting) detail in the {hql}[User Guide].
397
397
// The query language is discussed in great detail below in <<query-language>>.
398
398
399
399
Here we want to see how to execute a query via the `Session` or `EntityManager` API.
@@ -472,9 +472,11 @@ Or, if we're expecting it to return at most one result, we can use `getSingleRes
472
472
Book bookOrNull =
473
473
s.createSelectionQuery("from Book where isbn = ?1", Book.class)
474
474
.setParameter(1, isbn)
475
-
.getSingleResult();
475
+
.getSingleResultOrNull();
476
476
----
477
477
478
+
The difference, of course, is that `getSingleResult()` throws an exception if there is no matching row in the database, whereas `getSingleResultOrNull()` just returns `null`.
479
+
478
480
By default, Hibernate dirty checks entities in the persistence context before executing a query, in order to determine if the session should be flushed.
479
481
If there are many entities association with the persistence context, then this can be an expensive operation.
0 commit comments