Open christopher-mohr opened 2 years ago
Another use case is dto projection right now only works with repository methods implemented by micronaut-data without @Query
.
interface ThingRepository: PageableRepository<Thing, Int> {
// normal, works
fun findById(id: Int): Page<Thing>
// cannot duplicate method name and function name doesn't indicate
// that it's a subset of thing
fun findById(id: Int): Page<ThingSubsetDto>
// this can't be implemented
fun findSubsetDtoById(): Page<ThingSubsetDto>
// the dto projection doesn't work with @Query
@Query("from Thing t where t.id = :id")
fun findSubsetDtoById(id: Int): Page<ThingSubsetDto>
}
Is it planned to be developed? Its much needed feature
In Micronaut Data everything between find
and by
is a projection and you will get a compilation error if you are trying to reference something that doesn't exist. You can write String findNameById
to get only the name property from the entity. This kind of construction Spring Data doesn't support.
Maybe we can support suffix Returning
to allow findNameByIdReturningCustom
.
@rawilder Can you please create a sample project showing cases that don't work
github: https://github.com/rawilder/mn-data-dto-demo query dto method: https://github.com/rawilder/mn-data-dto-demo/blob/master/src/main/kotlin/dev/awilder/TestEntityRepo.kt#L22 failing test: https://github.com/rawilder/mn-data-dto-demo/blob/master/src/test/kotlin/dev/awilder/MnDataDtoDemoTest.kt#L26
In Micronaut Data everything between
find
andby
is a projection and you will get a compilation error if you are trying to reference something that doesn't exist. You can writeString findNameById
to get only the name property from the entity. This kind of construction Spring Data doesn't support.Maybe we can support suffix
Returning
to allowfindNameByIdReturningCustom
.
it isn't only about DTO, it's also about specifying which JOINs do you need in exact scenerio, right now repository methods always have to go with the most wide joining strategy and join relations not needed in given case but needed in another case.
Feature description
In some situations it would be convenient to be able to use descriptive text between the introducing keyword (such as
find
) andBy
in query method names as it is already possible in Spring Data.Description from the Spring Data documentation:
This would allow to use more expressive method names without affecting query derivation.
One use case would be if multiple methods that use the same property only differ by additional annotations, e.g.: