|
31 | 31 | import org.springframework.context.annotation.Bean; |
32 | 32 | import org.springframework.context.annotation.ComponentScan.Filter; |
33 | 33 | import org.springframework.context.annotation.FilterType; |
| 34 | +import org.springframework.core.convert.ConversionFailedException; |
34 | 35 | import org.springframework.data.jpa.domain.sample.EmployeeWithName; |
35 | 36 | import org.springframework.data.jpa.repository.JpaRepository; |
36 | 37 | import org.springframework.data.jpa.repository.Query; |
@@ -263,12 +264,30 @@ void derivedQueryLikeWithEmptyStringMatch() { |
263 | 264 | "Bilbo Baggins"); |
264 | 265 | } |
265 | 266 |
|
| 267 | + @Test // GH-1184 |
| 268 | + void mismatchedReturnTypeShouldCauseException() { |
| 269 | + assertThatExceptionOfType(ConversionFailedException.class) |
| 270 | + .isThrownBy(() -> repository.customQueryWithMismatchedReturnType()); |
| 271 | + } |
| 272 | + |
| 273 | + @Test // GH-1184 |
| 274 | + void alignedReturnTypeShouldWork() { |
| 275 | + assertThat(repository.customQueryWithAlignedReturnType()).containsExactly(new Object[][] { |
| 276 | + { "Frodo Baggins", "Frodo Baggins with suffix" }, { "Bilbo Baggins", "Bilbo Baggins with suffix" } }); |
| 277 | + } |
| 278 | + |
266 | 279 | @Transactional |
267 | 280 | public interface EmployeeWithNullLikeRepository extends JpaRepository<EmployeeWithName, Integer> { |
268 | 281 |
|
269 | 282 | @Query("select e from EmployeeWithName e where e.name like %:partialName%") |
270 | 283 | List<EmployeeWithName> customQueryWithNullableParam(@Nullable @Param("partialName") String partialName); |
271 | 284 |
|
| 285 | + @Query("select e.name, concat(e.name, ' with suffix') from EmployeeWithName e") |
| 286 | + List<EmployeeWithName> customQueryWithMismatchedReturnType(); |
| 287 | + |
| 288 | + @Query("select e.name, concat(e.name, ' with suffix') from EmployeeWithName e") |
| 289 | + List<Object[]> customQueryWithAlignedReturnType(); |
| 290 | + |
272 | 291 | @Query(value = "select * from EmployeeWithName as e where e.name like %:partialName%", nativeQuery = true) |
273 | 292 | List<EmployeeWithName> customQueryWithNullableParamInNative(@Nullable @Param("partialName") String partialName); |
274 | 293 |
|
|
0 commit comments