Skip to content

Commit 646b876

Browse files
committed
HHH-19364 augmentation javadoc examples
1 parent ed3a4dd commit 646b876

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

hibernate-core/src/main/java/org/hibernate/query/programmatic/SelectionSpecification.java

+28
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@ interface Augmentation<T> {
113113

114114
/**
115115
* Add an {@linkplain Augmentation augmentation} to the specification.
116+
* <p>
117+
* For example:
118+
* <pre>
119+
* SelectionSpecification.create(Book.class)
120+
* .addAugmentation((builder, query, book) ->
121+
* // augment the query via JPA Criteria API
122+
* query.where(builder.like(book.get(Book_.title), titlePattern)),
123+
* builder.greaterThan(book.get(Book_.pages), minPages))
124+
* .orderBy(builder.asc(book.get(Book_.isbn)))
125+
* .createQuery(session)
126+
* .getResultList();
127+
* </pre>
128+
* For complicated cases, a {@link org.hibernate.query.criteria.CriteriaDefinition}
129+
* may be used within an augmentation to eliminate repetitive explicit references to
130+
* the {@link CriteriaBuilder}.
131+
* <pre>
132+
* SelectionSpecification.create(Book.class)
133+
* .addAugmentation((builder, query, book) ->
134+
* // eliminate explicit references to 'builder'
135+
* new CriteriaDefinition<>(query) {{
136+
* where(like(entity.get(BasicEntity_.title), titlePattern),
137+
* greaterThan(book.get(Book_.pages), minPages));
138+
* orderBy(asc(book.get(Book_.isbn)));
139+
* }}
140+
* )
141+
* .createQuery(session)
142+
* .getResultList();
143+
* </pre>
116144
*
117145
* @param augmentation A function capable of modifying or augmenting a criteria query.
118146
*

0 commit comments

Comments
 (0)