title: SpingREST: Could not open JPA EntityManager for transaction; nested exception is org.hiberna
body: <p>When I start Postman to see my <code>SpringREST</code> service running I get following error:</p>
  
  <pre><code>{
      "timestamp": 1506965117328,
      "status": 500,
      "error": "Internal Server Error",
      "exception": "org.springframework.transaction.CannotCreateTransactionException",
      "message": "Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection",
      "path": "/api/matchs"
  }
  </code></pre>
  
  <p>I don't know where the error is, here are the classes of the project:</p>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.kaluzny&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-rest-api-postgresql&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&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.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&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;!-- Spring Boot --&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.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
          &lt;/dependency&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-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;!-- PostgreSQL--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;9.4-1201-jdbc41&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- Java EE --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.inject&lt;/groupId&gt;
              &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;
              &lt;version&gt;1&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;repackage&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Aplication.java</p>
  
  <pre><code>package com.kaluzny;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>MatchRestController.java</p>
  
  <pre><code>package com.kaluzny.web;
  
  import com.kaluzny.domain.*;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.*;
  
  import javax.inject.Inject;
  import java.util.Collection;
  
  @RestController
  @RequestMapping("/api/matchs")
  public class MatchRestController {
  
      private MatchRepository repository;
  
      @Inject
      public void setRepository(MatchRepository repository) {
          this.repository = repository;
      }
  
      @RequestMapping(
              method = RequestMethod.POST)
      public ResponseEntity&lt;?&gt; addMatch(@RequestBody Match match) {
          return new ResponseEntity&lt;&gt;(repository.save(match), HttpStatus.CREATED);
      }
  
      @RequestMapping(
              method = RequestMethod.GET)
      public ResponseEntity&lt;Collection&lt;Match&gt;&gt; getAllMatch() {
          return new ResponseEntity&lt;&gt;(repository.findAll(), HttpStatus.OK);
      }
  
      @RequestMapping(
              value = "/{idMatch}",
              method = RequestMethod.GET)
      public ResponseEntity&lt;Match&gt; getMatchWithIdMatch(@PathVariable Integer idMatch) {
          return new ResponseEntity&lt;&gt;(repository.findOne(idMatch), HttpStatus.OK);
      }
  
      @RequestMapping(
              value = "/{idMatch}",
              method = RequestMethod.PUT)
      public ResponseEntity&lt;Match&gt; updateMatchFromDB(@PathVariable("idMatch") Integer idMatch, @RequestBody Match match) {
  
          Match currentMatch = repository.findOne(idMatch);
          currentMatch.setIdMatch(match.getIdMatch());
          currentMatch.setNumberPlayers(match.getNumberPlayers());
          currentMatch.setWinner(match.getWinner());
          currentMatch.setScore(match.getScore());
          currentMatch.setNumberSpike(match.getNumberSpike());
          currentMatch.setNumberFireball(match.getNumberFireball());
          currentMatch.setNumberNuke(match.getNumberNuke());
  
          Match currentMatch1 = repository.findOne(idMatch);
  
  
  
          return new ResponseEntity&lt;&gt;(repository.save(currentMatch1), HttpStatus.OK);
      }
  
      @RequestMapping(
              value = "/{idMatch}",
              method = RequestMethod.DELETE)
      public void deleteMatchWithId(@PathVariable Integer idMatch) {
          repository.delete(idMatch);
      }
  
      @RequestMapping(
              method = RequestMethod.DELETE)
      public void deleteAllMatchs() {
          repository.deleteAll();
      }
  }
  </code></pre>
  
  <p>MatchRepository.java</p>
  
  <pre><code>package com.kaluzny.domain;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.rest.core.annotation.RepositoryRestResource;
  
  import java.util.List;
  
  @RepositoryRestResource
  public interface MatchRepository extends JpaRepository&lt;Match, Integer&gt; {
      List&lt;Match&gt; findByIdMatch(Integer idMatch);
  }
  </code></pre>
  
  <p>Match.java</p>
  
  <pre><code>package com.kaluzny.domain;
  
  import javax.persistence.*;
  
  @Entity
  public class Match {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
  
      private Integer idMatch;
      private Integer numberPlayers;
      private String winner;
      private Integer score;
      private Integer numberSpike;
      private Integer numberFireball;
      private Integer numberNuke;
  
  
      public Match(Integer idMatch, Integer numberPlayers, String winner, Integer score, Integer numberSpike, Integer numberFireball, Integer numberNuke) {
          this.idMatch = idMatch;
          this.numberPlayers = numberPlayers;
          this.winner = winner;
          this.score = score;
          this.numberSpike = numberSpike;
          this.numberFireball = numberFireball;
          this.numberNuke = numberNuke;
      }
  
      public Match() {
      }
  
      public void setIdMatch(Integer idMatch){
          this.idMatch = idMatch;
      }
  
      public Integer getIdMatch() {
          return idMatch;
      }
  
      public void setNumberPlayers(Integer numberPlayers){
          this.numberPlayers = numberPlayers;
      }
  
      public Integer getNumberPlayers(){
          return numberPlayers;
      }
  
      public void setWinner(String winner){
          this.winner = winner;
      }
  
      public String getWinner(){
          return winner;
      }
  
      public void setScore(Integer score){
          this.score = score;
      }
  
      public Integer getScore(){
          return score;
      }
  
      public void setNumberSpike(Integer numberSpike){
          this.numberSpike = numberSpike;
      }
  
      public Integer getNumberSpike(){
          return numberSpike;
      }
  
      public void setNumberFireball(Integer numberFireball){
          this.numberFireball = numberFireball;
      }
  
      public Integer getNumberFireball(){
          return numberFireball;
      }
  
      public void setNumberNuke(Integer numberNuke){
          this.numberNuke = numberNuke;
      }
  
      public Integer getNumberNuke(){
          return numberNuke;
      }
  
  
      @Override
      public String toString() {
          return "Partida{" +
              "Indentificador Partida: " + numberPlayers + '\'' +
              "Numero Jogadores: " + numberPlayers + '\'' +
              "Vencedor: "+ winner  + '\'' +
              "Pontuação: " + score + '\'' +
              "Numero de Espinhos: " + numberSpike + '\'' +
              "Numero de Fireball" + numberFireball + '\'' +
              "Numero de Nukes" + numberNuke + '}';
      }
  }
  </code></pre>
  
  <p>As I said I don't know where the problem is, I have fixed a few of them but this one has been difficult. </p>
  
  <p>Thanks everyone.</p>