I was going through Spring Data JPA Tutorial. I am confused on how does this framework work internally. Let me state specific scenario
The
I recommend to take a look at Query Creation section of the reference guide. It explains the rules pretty clearly.
For instance when you want to find User by first name and ignore case, you would use method name like findByFirstnameIgnoreCase
which would translate into condition like UPPER(x.firstame) = UPPER(?1)
.
By default when you have findByProperty
method, the match is exact, so if you want to have LIKE
functionality you would use method name findByFirstnameLike
which would in turn translate into condition where x.firstname like ?1
.
You can combine these keywords, but it can get a little crazy. Personally I prefer using @Query annotation for more complicated queries to avoid super long repository method names.