@@ -193,6 +193,42 @@ void noQueryShouldNotBeInvoked() {
193193 assertThatIllegalStateException ().isThrownBy (() -> query .getQueryMethod ());
194194 }
195195
196+ @ Test // GH-2551
197+ void customQueryWithQuestionMarksShouldWork () throws NoSuchMethodException {
198+
199+ QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
200+ EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
201+
202+ Method namedMethod = UserRepository .class .getMethod ("customQueryWithQuestionMarksAndNamedParam" , String .class );
203+ RepositoryMetadata namedMetadata = new DefaultRepositoryMetadata (UserRepository .class );
204+
205+ strategy .resolveQuery (namedMethod , namedMetadata , projectionFactory , namedQueries );
206+
207+ assertThatIllegalArgumentException ().isThrownBy (() -> {
208+
209+ Method jdbcStyleMethod = UserRepository .class .getMethod ("customQueryWithQuestionMarksAndJdbcStyleParam" ,
210+ String .class );
211+ RepositoryMetadata jdbcStyleMetadata = new DefaultRepositoryMetadata (UserRepository .class );
212+
213+ strategy .resolveQuery (jdbcStyleMethod , jdbcStyleMetadata , projectionFactory , namedQueries );
214+ }).withMessageContaining ("JDBC style parameters (?) are not supported for JPA queries." );
215+
216+ Method jpaStyleMethod = UserRepository .class .getMethod ("customQueryWithQuestionMarksAndNumberedStyleParam" ,
217+ String .class );
218+ RepositoryMetadata jpaStyleMetadata = new DefaultRepositoryMetadata (UserRepository .class );
219+
220+ strategy .resolveQuery (jpaStyleMethod , jpaStyleMetadata , projectionFactory , namedQueries );
221+
222+ assertThatIllegalArgumentException ().isThrownBy (() -> {
223+
224+ Method jpaAndJdbcStyleMethod = UserRepository .class
225+ .getMethod ("customQueryWithQuestionMarksAndJdbcStyleAndNumberedStyleParam" , String .class , String .class );
226+ RepositoryMetadata jpaAndJdbcMetadata = new DefaultRepositoryMetadata (UserRepository .class );
227+
228+ strategy .resolveQuery (jpaAndJdbcStyleMethod , jpaAndJdbcMetadata , projectionFactory , namedQueries );
229+ }).withMessageContaining ("Mixing of ? parameters and other forms like ?1 is not supported" );
230+ }
231+
196232 interface UserRepository extends Repository <User , Integer > {
197233
198234 @ Query ("something absurd" )
@@ -210,6 +246,18 @@ interface UserRepository extends Repository<User, Integer> {
210246 @ Query (value = "something absurd" , name = "my-query-name" )
211247 User annotatedQueryWithQueryAndQueryName ();
212248
249+ @ Query ("SELECT * FROM table WHERE (json_col->'jsonKey')::jsonb \\ ?\\ ? :param " )
250+ List <User > customQueryWithQuestionMarksAndNamedParam (String param );
251+
252+ @ Query ("SELECT * FROM table WHERE (json_col->'jsonKey')::jsonb \\ ?\\ ? ? " )
253+ List <User > customQueryWithQuestionMarksAndJdbcStyleParam (String param );
254+
255+ @ Query ("SELECT * FROM table WHERE (json_col->'jsonKey')::jsonb \\ ?\\ ? ?1 " )
256+ List <User > customQueryWithQuestionMarksAndNumberedStyleParam (String param );
257+
258+ @ Query ("SELECT * FROM table WHERE (json_col->'jsonKey')::jsonb \\ ?\\ ? ?1 and other_col = ? " )
259+ List <User > customQueryWithQuestionMarksAndJdbcStyleAndNumberedStyleParam (String param1 , String param2 );
260+
213261 // This is a named query with Sort parameter, which isn't supported
214262 List <User > customNamedQuery (String firstname , Sort sort );
215263 }
0 commit comments