From b16b1534a88635a2fca4fac45abbc8443c6349b2 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Fri, 25 Apr 2025 15:47:59 +0200 Subject: [PATCH 1/2] HHH-19386 MutationSpecificationImpl#getResultType must return null Returning `Void.class` causes the validation in `QuerySqmImpl` to fail with the error: ``` org.hibernate.query.IllegalQueryOperationException: Result type given for a non-SELECT Query [] ``` when the query is executed like in the example: ```java MutationSpecification mutationSpecification = MutationSpecification.create( ... ) session .createQuery(mutationSpecification.reference()) .executeUpdate(); ``` --- .../query/specification/internal/MutationSpecificationImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/specification/internal/MutationSpecificationImpl.java b/hibernate-core/src/main/java/org/hibernate/query/specification/internal/MutationSpecificationImpl.java index efde9b962c0b..47331c7f3200 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/specification/internal/MutationSpecificationImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/specification/internal/MutationSpecificationImpl.java @@ -79,7 +79,7 @@ public String getName() { @Override public Class getResultType() { - return Void.class; + return null; } @Override From b287863ca3c7a9fc4973e363e142398080fa0e59 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Fri, 25 Apr 2025 15:30:42 +0200 Subject: [PATCH 2/2] HHH-19386 Add test case --- .../dynamic/SimpleQuerySpecificationTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java index 5ee5ccad0648..34332e641e9e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/dynamic/SimpleQuerySpecificationTests.java @@ -160,6 +160,22 @@ void testSimpleMutationRestriction(SessionFactoryScope factoryScope) { assertThat( sqlCollector.getSqlQueries().get( 0 ) ).contains( " where be1_0.position between ? and ?" ); } + @Test + void testSimpleMutationRestrictionAsReference(SessionFactoryScope factoryScope) { + final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector(); + var deleteBasicEntity = MutationSpecification + .create( BasicEntity.class, "delete BasicEntity" ) + .restrict( Restriction.restrict( BasicEntity_.position, Range.closed( 1, 5 ) ) ) + .reference(); + factoryScope.inTransaction( session -> { + sqlCollector.clear(); + session.createQuery( deleteBasicEntity ).executeUpdate(); + } ); + + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ) ).contains( " where be1_0.position between ? and ?" ); + } + @Test void testRootEntityForm(SessionFactoryScope factoryScope) { final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector();