From b102a6e2c9b53bc2fa1798b7bd8a30dd09bf19f9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 24 Apr 2024 21:31:30 +0200 Subject: [PATCH] slightly improve format of error message Signed-off-by: Gavin King --- .../java/org/hibernate/query/sqm/internal/QuerySqmImpl.java | 6 ++++-- .../java/org/hibernate/orm/test/query/QueryApiTests.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java index 22cd5bf738..4bbd13d399 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java @@ -495,7 +495,8 @@ public class QuerySqmImpl } catch (IllegalQueryOperationException e) { // per JPA - throw new IllegalStateException( "Expecting a SELECT query : `" + hql + "`", e ); + throw new IllegalStateException( "Query executed via 'getResultList()' or 'getSingleResult()' must be a 'select' query [" + + hql + "]", e ); } } @@ -656,7 +657,8 @@ public class QuerySqmImpl } catch (IllegalQueryOperationException e) { // per JPA - throw new IllegalStateException( "Expecting a non-SELECT query : `" + hql + "`", e ); + throw new IllegalStateException( "Query executed via 'executeUpdate()' must be an 'insert', 'update', or 'delete' statement [" + + hql + "]", e ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryApiTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryApiTests.java index 371c6ec4fc..fe657e9683 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryApiTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/QueryApiTests.java @@ -41,7 +41,7 @@ public class QueryApiTests { catch (IllegalStateException ise) { assertThat( ise.getCause() ).isNotNull(); assertThat( ise.getCause() ).isInstanceOf( IllegalQueryOperationException.class ); - assertThat( ise.getMessage() ).endsWith( "`" + hql + "`" ); + assertThat( ise.getMessage() ).endsWith( "[" + hql + "]" ); } } @@ -57,7 +57,7 @@ public class QueryApiTests { catch (IllegalStateException ise) { assertThat( ise.getCause() ).isNotNull(); assertThat( ise.getCause() ).isInstanceOf( IllegalQueryOperationException.class ); - assertThat( ise.getMessage() ).endsWith( "`" + hql + "`" ); + assertThat( ise.getMessage() ).endsWith( "[" + hql + "]" ); } } ); @@ -70,7 +70,7 @@ public class QueryApiTests { catch (IllegalStateException ise) { assertThat( ise.getCause() ).isNotNull(); assertThat( ise.getCause() ).isInstanceOf( IllegalQueryOperationException.class ); - assertThat( ise.getMessage() ).endsWith( "`" + hql + "`" ); + assertThat( ise.getMessage() ).endsWith( "[" + hql + "]" ); } }