88import org .hibernate .query .IllegalMutationQueryException ;
99import org .hibernate .query .IllegalSelectQueryException ;
1010import org .hibernate .query .Order ;
11+ import org .hibernate .query .criteria .CriteriaDefinition ;
1112import org .hibernate .query .programmatic .MutationSpecification ;
1213import org .hibernate .query .programmatic .SelectionSpecification ;
1314import org .hibernate .query .range .Range ;
@@ -195,7 +196,7 @@ void testCriteriaForm(SessionFactoryScope factoryScope) {
195196 }
196197
197198 @ Test
198- void testCriteriaFormWithMutation (SessionFactoryScope factoryScope ) {
199+ void testAugmentation (SessionFactoryScope factoryScope ) {
199200 final SQLStatementInspector sqlCollector = factoryScope .getCollectingStatementInspector ();
200201
201202 factoryScope .inTransaction ( (session ) -> {
@@ -211,6 +212,27 @@ void testCriteriaFormWithMutation(SessionFactoryScope factoryScope) {
211212 assertThat ( sqlCollector .getSqlQueries ().get ( 0 ) ).contains ( " order by be1_0.position" );
212213 }
213214
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+ }
214236 @ Test
215237 void testBaseParameters (SessionFactoryScope factoryScope ) {
216238 final SQLStatementInspector sqlCollector = factoryScope .getCollectingStatementInspector ();
0 commit comments