fix formatting of two code examples in intro

This commit is contained in:
Gavin 2023-05-29 12:21:14 +02:00 committed by Christian Beikov
parent 41f817c34c
commit e17c1d7686
1 changed files with 8 additions and 4 deletions

View File

@ -757,13 +757,17 @@ For the most simple cases, Hibernate can infer the shape of the result set:
[source, java]
----
Book book = session.createNativeQuery("select * from Books where isbn = ?1", Book.class).getSingleResult();
Book book =
session.createNativeQuery("select * from Books where isbn = ?1", Book.class)
.getSingleResult();
String title = session.createNativeQuery("select title from Books where isbn = ?1", String.class).getSingleResult();
String title =
session.createNativeQuery("select title from Books where isbn = ?1", String.class)
.getSingleResult();
----
However, in general, there isn't enough information in the JDBC `ResultSetMetaData` to infer the mapping of columns to entity objects.
So for more complicated cases, you'll need to use the `@SqlResultSetMapping` annotation to define a named mapping, and pass the name to `createNativeQuery()`.
So for more complicated cases, you'll need to use the `@SqlResultSetMapping` annotation to define a named mapping, and pass the name to `createNativeQuery()`. This gets fairly messy, so we don't want to hurt your eyes by showing you an example of it.
By default, Hibernate doesn't flush the session before execution of a native query.
That's because the session is unaware of which modifications held in memory would affect the results of the query.
@ -789,7 +793,7 @@ List<Book> books =
.getResultList()
----
Or, alternative, we could tell Hibernate which modified state affects the results of the query:
Or, alternatively, we could tell Hibernate which modified state affects the results of the query:
[source,java]
----