Skip to content

Commit ab9eb9a

Browse files
committed
add examples to MutationQuery, SelectionQuery javadoc
1 parent f468d92 commit ab9eb9a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

hibernate-core/src/main/java/org/hibernate/query/MutationQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
* {@link #setParameter(int, Object)} allow arguments to be bound to named
4747
* and ordinal parameters defined by the query.
4848
* </ul>
49+
* <pre>
50+
* session.createMutationQuery("delete Draft where lastUpdated < local date - ?1 year")
51+
* .setParameter(1, years)
52+
* .executeUpdate();
53+
* </pre>
4954
*
5055
* @author Steve Ebersole
5156
*/

hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@
6666
* {@link #setParameter(int, Object)} allow arguments to be bound to named
6767
* and ordinal parameters defined by the query.
6868
* </ul>
69+
* A query which returns multiple results should be executed via
70+
* {@link #getResultList()}:
71+
* <pre>
72+
* List&lt;Book&gt; books =
73+
* session.createSelectionQuery("from Book left join fetch authors where title like :title")
74+
* .setParameter("title", title)
75+
* .setMaxResults(50)
76+
* .getResultList();
77+
* </pre>
78+
* A query which is expected to return exactly one on result should be executed
79+
* via {@link #getSingleResult()}, or, if it might not return a result,
80+
* {@link #getSingleResultOrNull()}:
81+
* <pre>
82+
* Book book =
83+
* session.createSelectionQuery("from Book where isbn = ?1")
84+
* .setParameter(1, isbn)
85+
* .getSingleResultOrNull();
86+
* </pre>
6987
* <p>
7088
* A query may have explicit <em>fetch joins</em>, specified using the syntax
7189
* {@code join fetch} in HQL, or via {@link jakarta.persistence.criteria.From#fetch}

0 commit comments

Comments
 (0)