spring-projects / spring-projects/spring-data-commons
Usage of findByIdOrNull Kotlin extension ignores proxy annotations
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
Imagine you define a repository in Kotlin like:
@Repository
interface MyRepository : CrudRepository<MyObject, String> {
@Cacheable("myCache")
override fun findById(id: String): Optional<MyObject>
}
And you then try to use this repository with the extension function of findByIdOrNull, you'll find that the @Cacheable annotation is ignored.
This is due to the fact that the findByIdOrNull will proxy the request to the interface method of findById(Object) instead of findById(String).
As the first one doesn't have any annotation in place, the annotation on the overridden method is never used.
I'm wondering if making the extension an inline extension would already fix the problem (but I didn't try that).
Thanks for having a look into this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.