8
8
import org .hibernate .query .IllegalMutationQueryException ;
9
9
import org .hibernate .query .IllegalSelectQueryException ;
10
10
import org .hibernate .query .Order ;
11
+ import org .hibernate .query .criteria .CriteriaDefinition ;
11
12
import org .hibernate .query .programmatic .MutationSpecification ;
12
13
import org .hibernate .query .programmatic .SelectionSpecification ;
13
14
import org .hibernate .query .range .Range ;
@@ -195,7 +196,7 @@ void testCriteriaForm(SessionFactoryScope factoryScope) {
195
196
}
196
197
197
198
@ Test
198
- void testCriteriaFormWithMutation (SessionFactoryScope factoryScope ) {
199
+ void testAugmentation (SessionFactoryScope factoryScope ) {
199
200
final SQLStatementInspector sqlCollector = factoryScope .getCollectingStatementInspector ();
200
201
201
202
factoryScope .inTransaction ( (session ) -> {
@@ -211,6 +212,27 @@ void testCriteriaFormWithMutation(SessionFactoryScope factoryScope) {
211
212
assertThat ( sqlCollector .getSqlQueries ().get ( 0 ) ).contains ( " order by be1_0.position" );
212
213
}
213
214
215
+ @ Test
216
+ void testAugmentationViaCriteriaDefinition (SessionFactoryScope factoryScope ) {
217
+ final SQLStatementInspector sqlCollector = factoryScope .getCollectingStatementInspector ();
218
+
219
+ factoryScope .inTransaction ( (session ) -> {
220
+ sqlCollector .clear ();
221
+ SelectionSpecification .create ( BasicEntity .class )
222
+ .addAugmentation ( (builder , query , entity ) ->
223
+ new CriteriaDefinition <>( query ) {{
224
+ where ( like ( entity .get ( BasicEntity_ .name ), "%" ),
225
+ equal ( entity .get ( BasicEntity_ .position ), 1 ) );
226
+ }}
227
+ )
228
+ .addOrdering ( Order .asc ( BasicEntity_ .position ) )
229
+ .createQuery ( session )
230
+ .getResultList ();
231
+ } );
232
+
233
+ assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
234
+ assertThat ( sqlCollector .getSqlQueries ().get ( 0 ) ).contains ( " order by be1_0.position" );
235
+ }
214
236
@ Test
215
237
void testBaseParameters (SessionFactoryScope factoryScope ) {
216
238
final SQLStatementInspector sqlCollector = factoryScope .getCollectingStatementInspector ();
0 commit comments