Skip to content

Commit cef19d7

Browse files
NathanQingyangXunathan.xu
andauthored
HHH-18605 fix some minor defects in Hibernate Query Language doc (#8941)
* HHH-18605 fix some minor defects in Hibernate Query Language doc Co-authored-by: nathan.xu <[email protected]>
1 parent 75ac785 commit cef19d7

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

documentation/src/main/asciidoc/querylanguage/Concepts.adoc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ For example:
334334

335335
[source,hql]
336336
----
337-
delete Author author where is empty author.books
337+
delete Author author where author.books is empty
338338
----
339339

340340
As in SQL, the presence or absence of the `from` keyword has absolutely no effect on the semantics of the `delete` statement.
@@ -419,7 +419,7 @@ The `queryExpression` in an `insert ... select` statement may be any valid `sele
419419
====
420420
This is checked during query compilation rather than allowing the type check to delegate to the database.
421421
This may cause problems when two Java types map to the same database type.
422-
For example, an attribute of type `LocalDateTime` and an attribute or type `Timestamp` both map to the SQL type `timestamp`, but are not considered assignable by the query compiler.
422+
For example, an attribute of type `LocalDateTime` and an attribute of type `Timestamp` both map to the SQL type `timestamp`, but are not considered assignable by the query compiler.
423423
====
424424

425425
There are two ways to assign a value to the `@Id` attribute:
@@ -577,7 +577,7 @@ Indeed, a fairly innocent-looking HQL query can easily translate to a SQL statem
577577
====
578578
We need to be a _bit_ careful about that, but actually it's usually a good thing.
579579
HQL makes it very easy to fetch all the data we need in a single trip to the database, and that's absolutely key to achieving high performance in data access code.
580-
Typically, it's much worse to fetch exactly the data we need, but in many round trips to the database server, than it is to fetch just a bit more data than what we're going to need, all a single SQL query.
580+
Typically, it's much worse to fetch exactly the data we need, but in many round trips to the database server, than it is to fetch just a bit more data than what we're going to need, all in a single SQL query.
581581
====
582582

583583
When there's no explicit `select` clause, a further abbreviation is sometimes possible.
@@ -609,7 +609,7 @@ The fundamental problem for Java is that it doesn't have tuple types.
609609
Queries in Hibernate return tables.
610610
Sure, often a column holds whole entity objects, but we're not restricted to returning a single entity, and we often write queries that return multiple entities in each result, or which return things which aren't entities.
611611

612-
So we're faced with the problem if representing such result sets, and, we're sad to say, there's no fully general and completely satisfying solution.
612+
So we're faced with the problem of representing such result sets, and, we're sad to say, there's no fully general and completely satisfying solution.
613613

614614
Let's begin with the easy case.
615615

@@ -641,7 +641,7 @@ When there are multiple expressions in the select list then, by default, and in
641641
[%unbreakable]
642642
----
643643
List<Object[]> results =
644-
entityManager.createQuery("select title, left(book.text, 200) from Book",
644+
entityManager.createQuery("select title, left(text, 200) from Book",
645645
Object[].class)
646646
.getResultList();
647647
for (var result : results) {
@@ -659,7 +659,7 @@ All we have to do is pass the class `Tuple` to `createQuery()`.
659659
[%unbreakable]
660660
----
661661
List<Tuple> tuples =
662-
entityManager.createQuery("select title as title, left(book.text, 200) as preamble from Book",
662+
entityManager.createQuery("select title as title, left(text, 200) as preamble from Book",
663663
Tuple.class)
664664
.getResultList();
665665
for (Tuple tuple : tuples) {
@@ -677,7 +677,7 @@ As an extension to JPA, and in a similar vein, Hibernate lets us pass `Map` or `
677677
[%unbreakable]
678678
----
679679
var results =
680-
entityManager.createQuery("select title as title, left(book.text, 200) as preamble from Book",
680+
entityManager.createQuery("select title as title, left(text, 200) as preamble from Book",
681681
Map.class)
682682
.getResultList();
683683
for (var map : results) {
@@ -689,7 +689,7 @@ for (var map : results) {
689689
[%unbreakable]
690690
----
691691
var results =
692-
entityManager.createQuery("select title, left(book.text, 200) from Book",
692+
entityManager.createQuery("select title, left(text, 200) from Book",
693693
List.class)
694694
.getResultList();
695695
for (var list : results) {
@@ -699,7 +699,7 @@ for (var list : results) {
699699
----
700700

701701
Unfortunately, not one of the types `Object[]`, `List`, `Map`, nor `Tuple` lets us access an individual item in a result tuple without a type cast.
702-
Sure `Tuple` does the type cast for us when we pass a class object to `get()`, but it's logically identical.
702+
Sure, `Tuple` does the type cast for us when we pass a class object to `get()`, but it's logically identical.
703703
Fortunately there's one more option, as we're about to see.
704704

705705
[NOTE]
@@ -717,7 +717,7 @@ This works extremely nicely with `record` types.
717717
record BookSummary(String title, String summary) {}
718718
719719
List<BookSummary> results =
720-
entityManager.createQuery("select title, left(book.text, 200) from Book",
720+
entityManager.createQuery("select title, left(text, 200) from Book",
721721
BookSummary.class)
722722
.getResultList();
723723
for (var result : results) {
@@ -762,7 +762,7 @@ For example, the JPA-standard `select new` construct packages the query results
762762
record BookSummary(String title, String summary) {}
763763
764764
List<BookSummary> results =
765-
entityManager.createQuery("select new BookSummary(title, left(book.text, 200)) from Book",
765+
entityManager.createQuery("select new BookSummary(title, left(text, 200)) from Book",
766766
BookSummary.class)
767767
.getResultList();
768768
for (var result : results) {

documentation/src/main/asciidoc/querylanguage/Expressions.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ An element of a compound path referring to a many-to-one or on-to-one associatio
259259

260260
[source,hql]
261261
----
262-
select treat(order.payment as CreditCardPayment).creditCardNumber from Order order
262+
select treat(order.payment as CreditCardPayment).cardNumber from Order order
263263
----
264264

265265
If an element of a compound path refers to a collection or many-valued association, it must have one of <<collection-functions,these special functions>> applied to it.
@@ -363,7 +363,7 @@ This default behavior may be changed using configuration property `hibernate.que
363363
Setting this property to `true` instructs Hibernate to produce SQL that emulates Java-style integer division (that is, `3/2 = 1`) on platforms where that is not the native semantics.
364364
====
365365

366-
When the operands are of different type, one of the operands is implicitly converted to _wider_ type, with wideness given, in decreasing order, by the list below:
366+
When the operands are of different types, one of the operands is implicitly converted to _wider_ type, with wideness given, in decreasing order, by the list below:
367367

368368
- `Double` (widest)
369369
- `Float`
@@ -382,7 +382,7 @@ Many more numeric operations are defined below, in <<exp-functions>>.
382382
Arithmetic involving dates, datetimes, and durations is quite subtle.
383383
Among the issues to consider are:
384384

385-
- There's two kinds of duration: year-day, and week-nanosecond durations.
385+
- There are two kinds of duration: year-day, and week-nanosecond durations.
386386
The first is a difference between dates; the second is a difference between datetimes.
387387
- We can subtract dates and datetimes, but we can't add them.
388388
- A Java-style duration has much too much precision, and so in order to use it for anything useful, we must somehow truncate it to something coarser-grained.
@@ -787,7 +787,7 @@ select trunc(local datetime, hour)
787787
----
788788

789789
Truncating a date, time or datetime value means obtaining a value of the same type in which all temporal units smaller than `field` have been pruned.
790-
For hours, minutes and second this means setting them to `00`. For months and days, this means setting them to `01`.
790+
For hours, minutes, and seconds this means setting them to `00`. For months and days, this means setting them to `01`.
791791

792792
[[string-functions]]
793793
==== Functions for working with strings
@@ -1019,7 +1019,7 @@ They're interpreted as referring to the collection as a whole.
10191019
| `keys()` | Maps | The keys of a map, collectively | ✖
10201020
| `values()` | Maps | The values of a map, collectively | ✖
10211021
|===
1022-
Application of one of these function produces an implicit subquery or implicit join.
1022+
Application of one of these functions produces an implicit subquery or implicit join.
10231023

10241024
This query has an implicit join:
10251025

documentation/src/main/asciidoc/querylanguage/From.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ select id, total
131131
from (
132132
select ord.id as id, sum(item.book.price * item.quantity) as total
133133
from Order as ord
134-
join Item as item
134+
join ord.items as item
135135
group by ord
136136
)
137137
where total > 100.0
@@ -145,7 +145,7 @@ select stuff.id, stuff.total
145145
from (
146146
select ord.id as id, sum(item.book.price * item.quantity) as total
147147
from Order as ord
148-
join Item as item
148+
join ord.items as item
149149
group by ord
150150
) as stuff
151151
where total > 100.0
@@ -347,9 +347,9 @@ An explicit join may narrow the type of the joined entity using `treat()`.
347347
[source, hql]
348348
----
349349
from Order as ord
350-
join treat(ord.payments as CreditCardPayment) as creditCardPayment
351-
where length(creditCardPayment.cardNumber) between 16 and 20
352-
select ord.id, creditCardPayment.cardNumber, creditCardPayment.amount
350+
join treat(ord.payments as CreditCardPayment) as ccp
351+
where length(ccp.cardNumber) between 16 and 20
352+
select ord.id, ccp.cardNumber, ccp.amount
353353
----
354354

355355
Here, the identification variable `ccp` declared to the right of `treat()` has the narrowed type `CreditCardPayment`, instead of the declared type `Payment`.
@@ -500,7 +500,7 @@ When a join involves a collection or many-valued association, the declared ident
500500
select publisher.name, author.name
501501
from Publisher as publisher
502502
join publisher.books as book
503-
join book.authors author
503+
join book.authors as author
504504
where author.name like :namePattern
505505
----
506506

@@ -518,7 +518,7 @@ These functions may be applied to the identification variable declared in a coll
518518
| Often optional.
519519
| `index()` | Any `List` with an index column | The index of the element in the list
520520
| For backward compatibility, it's also an alternative to ``key()``, when applied to a map.
521-
| `key()` | Any `Map` | The key of the entry in the list | If the key is of entity type, it may be further navigated.
521+
| `key()` | Any `Map` | The key of the entry in the map | If the key is of entity type, it may be further navigated.
522522
| `entry()` | Any `Map` | The map entry, that is, the `Map.Entry` of key and value.
523523
| Only legal as a terminal path, and only allowed in the `select` clause.
524524
|===
@@ -539,7 +539,7 @@ from Book as book
539539
select publisher.name, leadAuthor.name
540540
from Publisher as publisher
541541
join publisher.books as book
542-
join book.authors leadAuthor
542+
join book.authors as leadAuthor
543543
where leadAuthor.name like :namePattern
544544
and index(leadAuthor) == 0
545545
----

documentation/src/main/asciidoc/querylanguage/Relational.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ But it's better to specify the projection explicitly, except in the simplest cas
141141
==== Duplicate removal
142142

143143
The `distinct` keyword helps remove duplicate results from the query result list.
144-
It's only effect is to add `distinct` to the generated SQL.
144+
Its only effect is to add `distinct` to the generated SQL.
145145

146146
[[distinct-projection-query-example]]
147147
[source, hql]

0 commit comments

Comments
 (0)