add examples to MutationQuery, SelectionQuery javadoc

This commit is contained in:
Gavin King 2024-11-13 16:32:50 +01:00
parent f468d92c89
commit ab9eb9a496
2 changed files with 23 additions and 0 deletions

View File

@ -46,6 +46,11 @@ import jakarta.persistence.TemporalType;
* {@link #setParameter(int, Object)} allow arguments to be bound to named * {@link #setParameter(int, Object)} allow arguments to be bound to named
* and ordinal parameters defined by the query. * and ordinal parameters defined by the query.
* </ul> * </ul>
* <pre>
* session.createMutationQuery("delete Draft where lastUpdated < local date - ?1 year")
* .setParameter(1, years)
* .executeUpdate();
* </pre>
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */

View File

@ -66,6 +66,24 @@ import org.hibernate.graph.GraphSemantic;
* {@link #setParameter(int, Object)} allow arguments to be bound to named * {@link #setParameter(int, Object)} allow arguments to be bound to named
* and ordinal parameters defined by the query. * and ordinal parameters defined by the query.
* </ul> * </ul>
* A query which returns multiple results should be executed via
* {@link #getResultList()}:
* <pre>
* List&lt;Book&gt; books =
* session.createSelectionQuery("from Book left join fetch authors where title like :title")
* .setParameter("title", title)
* .setMaxResults(50)
* .getResultList();
* </pre>
* A query which is expected to return exactly one on result should be executed
* via {@link #getSingleResult()}, or, if it might not return a result,
* {@link #getSingleResultOrNull()}:
* <pre>
* Book book =
* session.createSelectionQuery("from Book where isbn = ?1")
* .setParameter(1, isbn)
* .getSingleResultOrNull();
* </pre>
* <p> * <p>
* A query may have explicit <em>fetch joins</em>, specified using the syntax * A query may have explicit <em>fetch joins</em>, specified using the syntax
* {@code join fetch} in HQL, or via {@link jakarta.persistence.criteria.From#fetch} * {@code join fetch} in HQL, or via {@link jakarta.persistence.criteria.From#fetch}