|
18 | 18 | * {@link jakarta.persistence.EntityManager}. They are declared here to allow reuse by
|
19 | 19 | * {@code StatelessSession}.
|
20 | 20 | * <p>
|
21 |
| - * Unlike the corresponding operations of {@code EntityManager}, operations for creating untyped |
22 |
| - * instances of {@code Query} are all marked as deprecated. Clients must migrate to the use of |
23 |
| - * the equivalent operations which accept a {@link Class} and return a typed {@code Query}. |
| 21 | + * Operations like {@link #createQuery(String, Class)}, {@link #createNamedQuery(String, Class)}, |
| 22 | + * and {@link #createNativeQuery(String, Class)} accept an instance indicating the return type |
| 23 | + * of the query. |
| 24 | + * <ul> |
| 25 | + * <li>The result type might be an {@linkplain jakarta.persistence.Entity entity} class, when |
| 26 | + * the query returns an entity: |
| 27 | + * <pre> |
| 28 | + * List<Book> allBooks = |
| 29 | + * session.createNativeQuery("select * from books order by title", Book.class) |
| 30 | + * .getResultList(); |
| 31 | + * </pre> |
| 32 | + * <li>It might be a {@linkplain org.hibernate.type.descriptor.java.JavaType basic type} like |
| 33 | + * {@code String} or {@code Long}: |
| 34 | + * <pre> |
| 35 | + * List<String> allTitles = |
| 36 | + * session.createNativeQuery("select distinct title from books order by title", String.class) |
| 37 | + * .getResultList(); |
| 38 | + * </pre> |
| 39 | + * <li>Finally, the result type might be a class used to package the elements of a {@code select} |
| 40 | + * list, such as a Java record with an appropriate constructor, {@code Map}, {@code List}, or |
| 41 | + * {@code Object[]}: |
| 42 | + * <pre> |
| 43 | + * record IsbnAndTitle(String isbn, String title) {} |
| 44 | + * |
| 45 | + * List<IsbnAndTitle> allBooks = |
| 46 | + * session.createNativeQuery("select isbn, title from books order by title", IsbnAndTitle.class) |
| 47 | + * .getResultList(); |
| 48 | + * </pre> |
| 49 | + * </ul> |
| 50 | + * For a {@linkplain #createQuery(CriteriaQuery) criteria query}, the result type is already |
| 51 | + * determined by {@link CriteriaQuery#getResultType()}. |
| 52 | + * |
| 53 | + * @apiNote Unlike the corresponding operations of {@code EntityManager}, operations for creating |
| 54 | + * untyped instances of {@code Query} are all marked as deprecated. Clients must migrate to the |
| 55 | + * use of the equivalent operations which accept a {@link Class} and return a typed {@code Query}. |
24 | 56 | *
|
25 | 57 | * @author Steve Ebersole
|
26 | 58 | */
|
|
0 commit comments