@@ -40,35 +40,34 @@ final class SimpleJpaQuery extends AbstractStringBasedJpaQuery {
4040 *
4141 * @param method must not be {@literal null}
4242 * @param em must not be {@literal null}
43- * @param countQueryString
43+ * @param sourceQuery the original source query, must not be {@literal null} or empty.
4444 * @param queryRewriter must not be {@literal null}
4545 * @param valueExpressionDelegate must not be {@literal null}
4646 */
47- public SimpleJpaQuery (JpaQueryMethod method , EntityManager em , @ Nullable String countQueryString ,
47+ public SimpleJpaQuery (JpaQueryMethod method , EntityManager em , @ Nullable String sourceQuery ,
4848 QueryRewriter queryRewriter , ValueExpressionDelegate valueExpressionDelegate ) {
49- this (method , em , method .getRequiredAnnotatedQuery (), countQueryString , queryRewriter , valueExpressionDelegate );
49+ this (method , em , method .getRequiredAnnotatedQuery (), sourceQuery , queryRewriter , valueExpressionDelegate );
5050 }
5151
5252 /**
5353 * Creates a new {@link SimpleJpaQuery} that encapsulates a simple query string.
5454 *
5555 * @param method must not be {@literal null}
5656 * @param em must not be {@literal null}
57- * @param queryString must not be {@literal null} or empty
57+ * @param sourceQuery the original source query, must not be {@literal null} or empty
5858 * @param countQueryString
5959 * @param queryRewriter
6060 * @param valueExpressionDelegate must not be {@literal null}
6161 */
62- public SimpleJpaQuery (JpaQueryMethod method , EntityManager em , String queryString , @ Nullable String countQueryString , QueryRewriter queryRewriter ,
63- ValueExpressionDelegate valueExpressionDelegate ) {
62+ public SimpleJpaQuery (JpaQueryMethod method , EntityManager em , String sourceQuery , @ Nullable String countQueryString ,
63+ QueryRewriter queryRewriter , ValueExpressionDelegate valueExpressionDelegate ) {
6464
65- super (method , em , queryString , countQueryString , queryRewriter , valueExpressionDelegate );
65+ super (method , em , sourceQuery , countQueryString , queryRewriter , valueExpressionDelegate );
6666
67- validateQuery (getQuery (). getQueryString () , "Validation failed for query for method %s" , method );
67+ validateQuery (getQuery (), "Validation failed for query %s for method %s" , method );
6868
6969 if (method .isPageQuery ()) {
70- validateQuery (getCountQuery ().getQueryString (),
71- String .format ("Count query validation failed for method %s" , method ));
70+ validateQuery (getCountQuery (), "Count query %s validation failed for method %s" , method );
7271 }
7372 }
7473
@@ -78,23 +77,24 @@ public SimpleJpaQuery(JpaQueryMethod method, EntityManager em, String queryStrin
7877 * @param query
7978 * @param errorMessage
8079 */
81- private void validateQuery (String query , String errorMessage , Object ... arguments ) {
80+ private void validateQuery (DeclaredQuery query , String errorMessage , JpaQueryMethod method ) {
8281
8382 if (getQueryMethod ().isProcedureQuery ()) {
8483 return ;
8584 }
8685
8786 EntityManager validatingEm = null ;
87+ var queryString = query .getQueryString ();
8888
8989 try {
9090 validatingEm = getEntityManager ().getEntityManagerFactory ().createEntityManager ();
91- validatingEm .createQuery (query );
91+ validatingEm .createQuery (queryString );
9292
9393 } catch (RuntimeException e ) {
9494
9595 // Needed as there's ambiguities in how an invalid query string shall be expressed by the persistence provider
96- // https://java.net/projects /jpa-spec/lists/jsr338-experts/archive/ 2012- 07/message/17
97- throw new IllegalArgumentException (String . format ( errorMessage , arguments ), e );
96+ // https://download.oracle.com/javaee-archive /jpa-spec.java.net/users/ 2012/ 07/0404.html
97+ throw new IllegalArgumentException (errorMessage . formatted ( query , method ), e );
9898
9999 } finally {
100100
0 commit comments