title: Why need @Query when I can write a method in Spring JPA
body: <p>I just got started with Spring JPA and I am reviewing code written by my coworker. 
  I see that he has been using the following code to find a Login object using username: </p>
  
  <pre><code>public interface LoginDao extends JpaRepository&lt;Login, Long&gt; {
          @Query("SELECT u FROM Login u WHERE LOWER(u.username) = LOWER(:username)")
          Login findByUsername(@Param("username") String username);
  }
  </code></pre>
  
  <p>Cant he just create a method like this: </p>
  
  <pre><code>@GET
  @Path("{username}")
  public Login getOne(@PathParam("username") String username) {
      Login login = loginDao.findOne(username);
      if (login == null) {
          throw new WebApplicationException(Response.Status.NOT_FOUND);
      } else {
          return login;
      }
  }
  </code></pre>
  
  <p>What are the fundamental advantages of using @Query rather than writing a method approach. Or am I plain wrong and both have different purposes.</p>
  
  <p>I personally dont want to write queries inside the code. I think mixing java with sql queries can make code look uglier. </p>
  
  <p>Our stack is java, JPA, Jersey, JAX-RS, Postgreql, Spring Boot, Hibernate</p>
  
  <p>Regards</p>