Skip to content

Commit f84c533

Browse files
committed
fix section on getSingleResultOrNull()
1 parent 88fea9a commit f84c533

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

documentation/src/main/asciidoc/introduction/Interacting.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ It's not necessary to dirty-check on entity instance in read-only mode.
383383

384384
Hibernate features three complementary ways to write queries:
385385

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,
387387
- the JPA _criteria query_ API, along with extensions, allowing almost any HQL query to be constructed programmatically via a typesafe API, and, of course
388388
- for when all else fails, _native SQL_ queries.
389389

@@ -393,7 +393,7 @@ Hibernate features three complementary ways to write queries:
393393
:hql: https://docs.jboss.org/hibernate/orm/6.2/userguide/html_single/Hibernate_User_Guide.html#query-language
394394

395395
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].
397397
// The query language is discussed in great detail below in <<query-language>>.
398398

399399
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
472472
Book bookOrNull =
473473
s.createSelectionQuery("from Book where isbn = ?1", Book.class)
474474
.setParameter(1, isbn)
475-
.getSingleResult();
475+
.getSingleResultOrNull();
476476
----
477477

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+
478480
By default, Hibernate dirty checks entities in the persistence context before executing a query, in order to determine if the session should be flushed.
479481
If there are many entities association with the persistence context, then this can be an expensive operation.
480482

0 commit comments

Comments
 (0)