Skip to content

Commit fc7fd97

Browse files
committed
mention that implicit instantiation works for native queries in doc
1 parent 65ed2bd commit fc7fd97

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,18 @@ for (var result : results) {
660660
----
661661
Notice that we're able to declare the `record` right before the line which executes the query.
662662

663-
Now, this is only _superficially_ more typesafe, since the query itself is not checked statically, and so we can't say it's objectively better.
663+
This works just as well with queries written in SQL:
664+
665+
[source,java]
666+
----
667+
record BookInfo(String isbn, String title, int pages) {}
668+
669+
List<BookInfo> resultList =
670+
session.createNativeQuery("select title, isbn, pages from Book", BookInfo.class)
671+
.getResultList();
672+
----
673+
674+
Now, this approach is only _superficially_ more typesafe, since the query itself is not checked statically, and so we can't say it's objectively better.
664675
But perhaps you find it more aesthetically pleasing.
665676
And if we're going to be passing query results around the system, the use of a `record` type is _much_ better.
666677

0 commit comments

Comments
 (0)