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/querylanguage/Concepts.adoc
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -334,7 +334,7 @@ For example:
334
334
335
335
[source,hql]
336
336
----
337
-
delete Author author where is empty author.books
337
+
delete Author author where author.books is empty
338
338
----
339
339
340
340
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
419
419
====
420
420
This is checked during query compilation rather than allowing the type check to delegate to the database.
421
421
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.
423
423
====
424
424
425
425
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
577
577
====
578
578
We need to be a _bit_ careful about that, but actually it's usually a good thing.
579
579
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.
581
581
====
582
582
583
583
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.
609
609
Queries in Hibernate return tables.
610
610
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.
611
611
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.
613
613
614
614
Let's begin with the easy case.
615
615
@@ -641,7 +641,7 @@ When there are multiple expressions in the select list then, by default, and in
641
641
[%unbreakable]
642
642
----
643
643
List<Object[]> results =
644
-
entityManager.createQuery("select title, left(book.text, 200) from Book",
644
+
entityManager.createQuery("select title, left(text, 200) from Book",
645
645
Object[].class)
646
646
.getResultList();
647
647
for (var result : results) {
@@ -659,7 +659,7 @@ All we have to do is pass the class `Tuple` to `createQuery()`.
659
659
[%unbreakable]
660
660
----
661
661
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",
663
663
Tuple.class)
664
664
.getResultList();
665
665
for (Tuple tuple : tuples) {
@@ -677,7 +677,7 @@ As an extension to JPA, and in a similar vein, Hibernate lets us pass `Map` or `
677
677
[%unbreakable]
678
678
----
679
679
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",
681
681
Map.class)
682
682
.getResultList();
683
683
for (var map : results) {
@@ -689,7 +689,7 @@ for (var map : results) {
689
689
[%unbreakable]
690
690
----
691
691
var results =
692
-
entityManager.createQuery("select title, left(book.text, 200) from Book",
692
+
entityManager.createQuery("select title, left(text, 200) from Book",
693
693
List.class)
694
694
.getResultList();
695
695
for (var list : results) {
@@ -699,7 +699,7 @@ for (var list : results) {
699
699
----
700
700
701
701
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.
703
703
Fortunately there's one more option, as we're about to see.
704
704
705
705
[NOTE]
@@ -717,7 +717,7 @@ This works extremely nicely with `record` types.
717
717
record BookSummary(String title, String summary) {}
718
718
719
719
List<BookSummary> results =
720
-
entityManager.createQuery("select title, left(book.text, 200) from Book",
720
+
entityManager.createQuery("select title, left(text, 200) from Book",
721
721
BookSummary.class)
722
722
.getResultList();
723
723
for (var result : results) {
@@ -762,7 +762,7 @@ For example, the JPA-standard `select new` construct packages the query results
762
762
record BookSummary(String title, String summary) {}
763
763
764
764
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",
Copy file name to clipboardExpand all lines: documentation/src/main/asciidoc/querylanguage/Expressions.adoc
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -259,7 +259,7 @@ An element of a compound path referring to a many-to-one or on-to-one associatio
259
259
260
260
[source,hql]
261
261
----
262
-
select treat(order.payment as CreditCardPayment).creditCardNumber from Order order
262
+
select treat(order.payment as CreditCardPayment).cardNumber from Order order
263
263
----
264
264
265
265
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
363
363
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.
364
364
====
365
365
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:
367
367
368
368
- `Double` (widest)
369
369
- `Float`
@@ -382,7 +382,7 @@ Many more numeric operations are defined below, in <<exp-functions>>.
382
382
Arithmetic involving dates, datetimes, and durations is quite subtle.
383
383
Among the issues to consider are:
384
384
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.
386
386
The first is a difference between dates; the second is a difference between datetimes.
387
387
- We can subtract dates and datetimes, but we can't add them.
388
388
- 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.
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
353
353
----
354
354
355
355
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
500
500
select publisher.name, author.name
501
501
from Publisher as publisher
502
502
join publisher.books as book
503
-
join book.authors author
503
+
join book.authors as author
504
504
where author.name like :namePattern
505
505
----
506
506
@@ -518,7 +518,7 @@ These functions may be applied to the identification variable declared in a coll
518
518
| Often optional.
519
519
| `index()` | Any `List` with an index column | The index of the element in the list
520
520
| 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.
522
522
| `entry()` | Any `Map` | The map entry, that is, the `Map.Entry` of key and value.
523
523
| Only legal as a terminal path, and only allowed in the `select` clause.
0 commit comments