title: What rules govern using @MOdify and @Query in JPA Repository?
body: <p>Now that my project is successfully completed, we are trying to document lessons learned. One that still confuses me is the following: </p>
  
  <p>We have a database of addresses, and needed to autocomplete when a User started typing in a street name. Using JPA repository, we implemented a PString class (simply a persistent wrapper for a String), and then implemented this interface:</p>
  
  <pre><code>@RepositoryRestResource(collectionResourceRel = "locations", path = "locations")
  public interface LocationRepository extends JpaRepository&lt;Location, Integer&gt;, LocationRepositoryCustom {
     List&lt;Location&gt; findByStreetNameAndCommunity_ID(@Param("street") String streetName, @Param("commId") Integer commId);
  
     @Modifying
     @Query("select distinct x.streetName from Location x where x.streetName like :street%")
     List&lt;PString&gt; findStreetNameStartingWith(@Param("street") String streetName);
  }
  </code></pre>
  
  <p>Trying to call locations/search/findStreetNameStartingWith?street=N%20College over the web resulted in:</p>
  
  <p>{"cause":null,"message":"PersistentEntity must not be null!"}</p>
  
  <p>However, we added a controller to call the method:</p>
  
  <pre><code>@RestController
  @RequestMapping("/custom/locations")
  public class LocationController {
  
     @Autowired
     private LocationRepository repo;
  
     @RequestMapping(value = "/findStreetNamesStartingWith", method=RequestMethod.GET)
     public List&lt;PString&gt; findStreetNameStartingWith(
          @Param("streetName") String streetName) {
  
        return repo.findStreetNameStartingWith(streetName);
     }
  }
  </code></pre>
  
  <p>Calling /custom/locations/findStreetNamesStartingWith?streetName=N%20Coll returns the expected three results. Why does the method not work if called directly, but runs like a greyhound when we pipe it through a controller?</p>