Skip to content

more prominent discussion of result types #10125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ private RuntimeException convertNamedQueryException(RuntimeException e) {
// it also expects an IllegalArgumentException, so wrap UnknownNamedQueryException
return new IllegalArgumentException( e.getMessage(), e );
}
else if ( e instanceof IllegalArgumentException) {
else if ( e instanceof IllegalArgumentException ) {
return e;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,41 @@
* {@link jakarta.persistence.EntityManager}. They are declared here to allow reuse by
* {@code StatelessSession}.
* <p>
* Unlike the corresponding operations of {@code EntityManager}, operations for creating untyped
* instances of {@code Query} are all marked as deprecated. Clients must migrate to the use of
* the equivalent operations which accept a {@link Class} and return a typed {@code Query}.
* Operations like {@link #createQuery(String, Class)}, {@link #createNamedQuery(String, Class)},
* and {@link #createNativeQuery(String, Class)} accept an instance indicating the return type
* of the query.
* <ul>
* <li>The result type might be an {@linkplain jakarta.persistence.Entity entity} class, when
* the query returns an entity:
* <pre>
* List&lt;Book&gt; allBooks =
* session.createNativeQuery("select * from books order by title", Book.class)
* .getResultList();
* </pre>
* <li>It might be a {@linkplain org.hibernate.type.descriptor.java.JavaType basic type} like
* {@code String} or {@code Long}:
* <pre>
* List&lt;String&gt; allTitles =
* session.createNativeQuery("select distinct title from books order by title", String.class)
* .getResultList();
* </pre>
* <li>Finally, the result type might be a class used to package the elements of a {@code select}
* list, such as a Java record with an appropriate constructor, {@code Map}, {@code List}, or
* {@code Object[]}:
* <pre>
* record IsbnAndTitle(String isbn, String title) {}
*
* List&lt;IsbnAndTitle&gt; allBooks =
* session.createNativeQuery("select isbn, title from books order by title", IsbnAndTitle.class)
* .getResultList();
* </pre>
* </ul>
* For a {@linkplain #createQuery(CriteriaQuery) criteria query}, the result type is already
* determined by {@link CriteriaQuery#getResultType()}.
*
* @apiNote Unlike the corresponding operations of {@code EntityManager}, operations for creating
* untyped instances of {@code Query} are all marked as deprecated. Clients must migrate to the
* use of the equivalent operations which accept a {@link Class} and return a typed {@code Query}.
*
* @author Steve Ebersole
*/
Expand Down
Loading