title: Use JPA Spring boot with SQL Server
body: <p>I want to use JPA in Spring boot with SQL Server by STS
  This is my table: </p>
  
  <p><img src="https://i.stack.imgur.com/Iovsc.png" alt="enter image description here"></p>
  
  <p>MAVEN</p>
  
  <pre><code>&lt;dependencies&gt;
  
      &lt;dependency&gt;
      &lt;groupId&gt;com.hynnet&lt;/groupId&gt;
      &lt;artifactId&gt;sqljdbc-chs&lt;/artifactId&gt;
      &lt;version&gt;4.0.2206.100&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;commons-lang&lt;/groupId&gt;
      &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
      &lt;version&gt;2.2&lt;/version&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-jdbc&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.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;
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>spring.datasource.driver-class-  name=com.microsoft.sqlserver.jdbc.SQLServerDriver
  spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=quanlybanhang
  spring.datasource.username=sa
  spring.datasource.password=1
  spring.jpa.hibernate.ddl-auto=create
  spring.datasource.initialize=true
  spring.jpa.database=SQL_SERVER
  </code></pre>
  
  <p>Model.Account.class</p>
  
  <pre><code>  @Entity
    @Table(name="taikhoan",uniqueConstraints=@UniqueConstraint(columnNames = {    "tendangnhap" }) )
   public class Account {
   @Id @GeneratedValue(strategy=GenerationType.AUTO)
   private int id;
   @NotNull
  
  private String tendangnhap;
  @NotNull
  private String matkhau;
  public Account(String tendangnhap, String matkhau) {
      super();
      this.tendangnhap = tendangnhap;
   this.matkhau = matkhau;
  }
  public Account() {
      super();
  }
  public int getId() {
      return id;
  }
  public void setId(int id) {
      this.id = id;
  }
  public String getTendangnhap() {
      return tendangnhap;
  }
  
  public void setTendangnhap(String tendangnhap) {
      this.tendangnhap = tendangnhap;
  }
  public String getMatkhau() {
      return matkhau;
  }
  public void setMatkhau(String matkhau) {
      this.matkhau = matkhau;
  }   
  }
  </code></pre>
  
  <p>interface AccountDAO</p>
  
  <pre><code>public interface AccountDAO extends JpaRepository&lt;Account, Integer&gt;{
  
  }
  </code></pre>
  
  <p>ServiceAccount.class</p>
  
  <pre><code>@Service
  public class ServerAccount {
      @Autowired
      AccountDAO server;
      public void them(Account acc){
          server.save(acc);   
      }
      public List&lt;Account&gt; lietke(){
  
          return server.findAll();    
      }
  }
  </code></pre>
  
  <p>ServicesAccount.class</p>
  
  <pre><code>@Service
  public class ServerAccount {
      @Autowired
      AccountDAO server;
  
      Account acc=new Account("khang", "1");
  
      public void addAccount(){
          server.save(acc);
      }
  
  
      public List&lt;Account&gt; lietke(){
  
          return server.findAll();    
      }
  
  }
  </code></pre>
  
  <p>I called method addAccount() in Controller and this is Exception I got </p>
  
  <p>"java.lang.NoClassDefFoundError: org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor"</p>
  
  <p>"Caused by: java.lang.ClassNotFoundException: org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"</p>
  
  <p>Please help me fix this exception. Thanks!!!</p>