Using @NaturalId for cache
I'm using @NaturalId annotation in my User.email.
I expected that my findByEmail(String email) would enable to search in first level cache or second level cache.
But in log, cache does not work as I think.
Every findByEmail method were access DB.
I used bySimpleNaturalId() for my purpose, but it's very hassle.
Please make @NaturalId access to cache enable
This is an interesting proposal. Lets wait until it is actually part of JPA: https://github.com/eclipse-ee4j/jpa-api/issues/320
We try to avoid implementation specifics in Spring Data JPA.
Is it really necessary having to go through findByNaturalId()? If you already mark the natural id foo field as @NaturalId, perhaps it can be some way to make loadByFoo automatically marked internally as a NaturalId, and through reflection, cache it
Yes, because Spring Data JPA certainly won't get into caching itself.
I meant caching it though hinting the JPA Provider. Idk, it's just that it feels so antifunctional to use findByNaturalId() when findByEmail(), findByISBN() or findByName() is so readable :,(