From 02b7c5afb5d19155beb2b55aaadb676881d32416 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Thu, 2 Mar 2023 23:32:48 +0100 Subject: [PATCH] Add a note w/ respect to native queries and inheritance Signed-off-by: Jan Schatteman --- .../asciidoc/userguide/chapters/query/native/Native.adoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/documentation/src/main/asciidoc/userguide/chapters/query/native/Native.adoc b/documentation/src/main/asciidoc/userguide/chapters/query/native/Native.adoc index 2938c377e5..21a8649812 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/query/native/Native.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/query/native/Native.adoc @@ -342,6 +342,15 @@ include::{doc-emeddable-example-dir}/SQLTest.java[tags=sql-hibernate-dto-query-e There's no such equivalent in Jakarta Persistence because the `jakarta.persistence.Query` interface does not define a `setResultTransformer` method equivalent. ==== +[IMPORTANT] +==== +When materializing a native query result as a polymorphic entity, it is important to understand that both the `JOINED` as well as the `TABLE_PER_CLASS` inheritance strategies require that the native query also include a special `clazz_` select item, which returns the subclass id that Hibernate needs to determine the concrete Java type for a row. + +The subclass id is determined based on some order and the base class of the entity hierarchy has the number 0. + +Refer to the respective sections in the inheritance chapter for examples of this. +==== + The above query will return a list of `PersonSummaryDTO` which has been instantiated and injected the values of `id` and `name` into its corresponding properties or fields. [[sql-inheritance-query]]