title: Spring Data JPA : java.sql.SQLException: Column 'id' not found
body: <p>Trying to return list from column named <code>make</code> causes error in console where column <code>id</code> is not found.  The column named <code>id</code> is on the table but not sure why it is not recognized.  </p>
  
  <p>Car.java</p>
  
  <pre><code> package com.example.demo;
  
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  
  @Entity
  public class Car {
  
      @Id
      private String id;
  
      private String make;
      private String model;
      private String year;
  
  
      public Car() {
      }
  
      public Car(String id, String make, String model, String year) {
          this.id = id;
          this.make = make;
          this.model = model;
          this.year = year;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getMake() {
          return make;
      }
  
      public void setMake(String make) {
          this.make = make;
      }
  
      public String getModel() {
          return model;
      }
  
      public void setModel(String model) {
          this.model = model;
      }
  
      public String getYear() {
          return year;
      }
  
      public void setYear(String year) {
          this.year = year;
      }
  }
  </code></pre>
  
  <p>CarRepository.java</p>
  
  <pre><code>package com.example.demo;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  
  import java.util.List;
  
  public interface CarRepository extends JpaRepository&lt;Car, String&gt; {
      @Query(value="SELECT make FROM car", nativeQuery=true)
      List&lt;Car&gt; getAllMakes();
  }
  
  </code></pre>
  
  <p>CarController.java</p>
  
  <pre><code>package com.example.demo;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PostMapping;
  
  
  @Controller
  public class CarController {
  
  
  
      @Autowired
      private CarService carService;
  
      @Autowired
      private CarRepository carRepository;
  
  
  
      @GetMapping("/car")
      public String carForm(Model model) {
          model.addAttribute("car", new Car());
          model.addAttribute("cars", carService.getAllCars());
          return "car";
      }
  
      @PostMapping("/car")
          carService.addCar(car);
          return "redirect:/car";
      }
  
  
  
      @GetMapping("/list")
      public String carMakeList(Model model){
          model.addAttribute("list", carRepository.getAllMakes());
          return "list";
      }
  
  
  }
  </code></pre>
  
  <p>list.html</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Car List&lt;/h1&gt;
  
  &lt;table&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Id&lt;/th&gt;
          &lt;th&gt;Make&lt;/th&gt;
          &lt;th&gt;Model&lt;/th&gt;
          &lt;th&gt;Year&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;tr th:if="${!list}"&gt;
          &lt;td colspan="2"&gt; No Cars Available&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr th:each="car : ${list}"&gt;
  
          &lt;td&gt;&lt;span th:text="${car.make}"&gt;Make&lt;/span&gt;&lt;/td&gt;
  
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <pre><code>2019-08-30 10:12:31.008 ERROR 26538 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Column 'id' not found.
  2019-08-30 10:12:31.026 ERROR 26538 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [SELECT make FROM car]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
  
  java.sql.SQLException: Column 'id' not found.
  </code></pre>