I've been using Spring Data's querydsl support in order to do filtering on my domain entities. However, when I try to override the customize method of QuerydslBinderCustomizer in my repository, I get an IllegalArgumentException as follows:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract void com.my.project.repository.TripRepository.customize(org.springframework.data.querydsl.binding.QuerydslBindings,com.my.project.domain.trip.QTrip)! No property customize found for type Trip!
My repository is defined as follows:
@Repository
interface TripRepository : PagingAndSortingRepository<Trip, Long>, QuerydslPredicateExecutor<Trip>, QuerydslBinderCustomizer<QTrip> {
fun findByState(tripState: TripState): List<Trip>
override fun customize(bindings: QuerydslBindings, root: QTrip) {
bindings.excluding(root.anonymousToken)
}
}
It seems like PagingAndSortingRepository is searching for a customize field on my Trip entity, despite it being a method override from another interface. I've tried adding an empty @Query annotation to the customize method hoping that it would be ignored to no avail.
Is there any workaround for this issue?
Update
I haven't managed to get this working in Kotlin. I ended up (begrudgingly) converting my repository classes to Java, which solved the problem.
Update
The solution for this issue is to use the @JvmDefault annotation on the customize method.
@Repository
interface TripRepository : PagingAndSortingRepository<Trip, Long>, QuerydslPredicateExecutor<Trip>, QuerydslBinderCustomizer<QTrip> {
fun findByState(tripState: TripState): List<Trip>
@JvmDefault
override fun customize(bindings: QuerydslBindings, root: QTrip) {
bindings.excluding(root.anonymousToken)
}
}