title: Spring boot postgreSQL
body: <p>I am writing a web app with Spring Boot, Hibernate and PostgreSQL. I want to learn how to save things in DB, but now I can`t resolve my problem. I am getting an error caused by my controller by line:</p>
  
  <pre><code>silniaRepository.save(silniaDB);
  </code></pre>
  
  <p>error is just:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException</p>
  </blockquote>
  
  <p>there is my pom:  </p>
  
  <pre><code>&lt;name&gt;silnia&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.2.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.reporting.outputEncoding&gt;UTF-    8&lt;/project.reporting.outputEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;8.1.5.v20120716&lt;/version&gt;
           &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>part of my controller:</p>
  
  <pre><code>@Controller
  public class SilniaController {
    @Autowired
    public SilniaService silniaService;
    public SilniaRepository silniaRepository;
    public SilniaDB silniaDB;
  
    @RequestMapping("/db")
    @ResponseBody
    public String testMethod() {
  
      StringBuilder response = new StringBuilder();
  
      SilniaDB silniaDB = new SilniaDB()
              .setNumber1(23);
      silniaRepository.save(silniaDB);
  
      for (SilniaDB i : silniaRepository.findAll()) {
          response.append(i).append("&lt;br&gt;");
      }
  
      return response.toString();
  }
  </code></pre>
  
  <p>my DB model:</p>
  
  <pre><code>@Entity
  public class SilniaDB {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Column
      private int number;
  
      public int getNumber() {
          return number;
      }
  
      public void setNumber (int number){this.number=number;}
  
      public SilniaDB setNumber1(int number) {
          this.number = number;
          return this;
      }
  
      public SilniaDB withNumber(final int number) {
          this.number = number;
          return this;
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
      @Override
      public String toString() {
          return "TaskEntity{" +
                  "id=" + id +
                  "number=" + number +
                  '}';
      }
  }
  </code></pre>
  
  <p>and typical repository interface:</p>
  
  <pre><code>@Repository
  public interface SilniaRepository extends CrudRepository&lt;SilniaDB, Long&gt; {
  
      public SilniaDB findByNumber(Integer number);
  }
  </code></pre>
  
  <p>I really spent a lot of time on that issue. Thanks in advance for every comment or answer.</p>