I went through the Spring Data JPA Tutorial. I am confused about how this structure works internally. Let me specify a specific scenario.
Code has been defined
public List<Location> getLocationByStateName(String name) {
@SuppressWarnings("unchecked")
List<Location> locs = entityManager
.createQuery("select l from Location l where l.state like :state")
.setParameter("state", name + "%").getResultList();
return locs;
}
It was simply replaced by the following interface
@Repository
public interface LocationJPARepository extends JpaRepository<Location, Long> {
List<Location> findByStateLike(String stateName);
}
And the corresponding test case worked fine
@Test
public void testFindWithLike() throws Exception {
List<Location> locs = locationRepository.getLocationByStateName("New");
assertEquals(4, locs.size());
}
New test case
@Test
public void testFindWithLike() throws Exception {
List<Location> locs = locationJPARepository.findByStateLike("New");
assertEquals(4, locs.size());
}
My question
- As the framework knows, am I looking for an exact match using = or a partial match using an SQL statement (can't it be a method name?)
- If for some reason this decides that I am looking for a partial match, then there are still auxiliary parameters ... for example, the name% or% name or% name% ...
- Just like this solves the matter, how is it important? (I can be case insensitive using SQL, as with toUpper (), i.e. by comparing everything in uppercase)
- ( ) EXACT SQL , ?
, . , .