Skip to content

Commit c835124

Browse files
committed
Polishing.
Align assignability check for modifying execution. See #4015
1 parent d90d054 commit c835124

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ public ModifyingExecution(JpaQueryMethod method, EntityManager em) {
248248

249249
Class<?> returnType = method.getReturnType();
250250

251-
boolean isVoid = ClassUtils.isAssignable(returnType, Void.class);
252-
boolean isInt = ClassUtils.isAssignable(returnType, Integer.class);
251+
boolean isVoid = org.springframework.data.util.ReflectionUtils.isVoid(returnType);
252+
boolean isNumber = ClassUtils.isAssignable(Number.class, returnType);
253253

254-
Assert.isTrue(isInt || isVoid,
255-
"Modifying queries can only use void or int/Integer as return type; Offending method: " + method);
254+
Assert.isTrue(isNumber || isVoid,
255+
"Modifying queries can only use void, int/Integer, or long/Long as return type; Offending method: " + method);
256256

257257
this.em = em;
258258
this.flush = method.getFlushAutomatically();

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpaQueryExecutionUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void allowsMethodReturnTypesForModifyingQuery() {
169169
@Test
170170
void modifyingExecutionRejectsNonIntegerOrVoidReturnType() {
171171

172-
when(method.getReturnType()).thenReturn((Class) Long.class);
172+
when(method.getReturnType()).thenReturn((Class) String.class);
173173
assertThatIllegalArgumentException().isThrownBy(() -> new ModifyingExecution(method, em));
174174
}
175175

0 commit comments

Comments
 (0)