title: "java.lang.ClassNotFoundException: javax.persistence.Persistence" error in hibernate JPA project based on MVC
body: <p>I try to create a web application based on <code>MVC</code> structure and by <code>Hibernate JPA</code> .</p>
  
  <p>I  want save data form in database . for this job , I get data in <code>servlet</code> and call a method in <code>personManager</code> class in <code>business logic "bl"</code> package .</p>
  
  <p>this method most get data and Saves them but present this error : </p>
  
  <pre><code>10-Dec-2018 11:15:07.463 SEVERE [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [manager] in context with path [] threw exception [Servlet execution threw an exception] with root cause
  java.lang.ClassNotFoundException: javax.persistence.Persistence
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1309)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137)
  at util.JPAProvider.&lt;clinit&gt;(JPAProvider.java:13)
  at model.bl.PersonManager.&lt;init&gt;(PersonManager.java:24)
  at controller.Manager.service(Manager.java:81)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
  at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>servlet class :</p>
  
  <pre><code>  public void service (HttpServletRequest request , HttpServletResponse response)throws IOException, ServletException
  {
      String username= request.getParameter("choose-username");
      String password= request.getParameter("choose-password");
      String repeatPass= request.getParameter("repeat-password");
      String email = request.getParameter("email");
      HttpSession session = request.getSession();
  
       try {
              PersonManager personManager = new PersonManager();
              personManager.addUser(username , password , email , "female");
              response.sendRedirect("/views/welcome.jsp");
          } catch (Exception e)
          {
              request.getRequestDispatcher("/views/register.jsp").forward(request, response);
          }
      }
  </code></pre>
  
  <p>JPAProvider class:</p>
  
  <pre><code>public class JPAProvider {
  
  private static final EntityManagerFactory entityManagerFactory;//instate of session for connect to database
  static{
      entityManagerFactory  = Persistence.createEntityManagerFactory("MyConnection");
  }
  
  public static EntityManagerFactory getEntityManagerFactory() {
      return entityManagerFactory;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public class PersonManager {</p>
  
  <pre><code>EntityManager entityManager=null;
  EntityTransaction entityTransaction=null;
  
  public PersonManager() {
       entityManager = JPAProvider.getEntityManagerFactory().createEntityManager();//session factory
       entityTransaction = entityManager.getTransaction();
  }
  
  public Boolean addUser(String username , String password , String email , String sex)
  {
      try{
          entityTransaction.begin();
          Person person = new Person();
          person.setUsername(username);
          person.setPassword(password);
          person.setEmail(email);
          person.setSex(sex);
          entityManager.persist(person);
          entityTransaction.commit();
          entityManager.close();
  
      }catch (Exception e){
          System.out.println(e.getStackTrace());
          System.out.println("addUser failed");
      }
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Person class :</p>
  
  <pre><code>package model.entity;
  import model.bl.PersonManager;
  import javax.persistence.*;
  import java.io.Serializable;
  import java.util.List;
  
  //mapping class to table
  @Entity (name = "person")
  @Table(name = "USERS")
  @EntityListeners(value = PersonManager.class)
  
  public class Person implements Serializable
  {
  
  @Id // create id and fill auto by sequence in database
  @Column(name="UID" ,columnDefinition = "NUMBER" )
  @SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
  @GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
  private long uId;
  
  
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
  private List&lt;Pictures&gt; picturesList;
  
  
  @Basic
  @Column (name = "USERNAME" , columnDefinition = "NVARCHAR2(30)" , nullable = false , unique = true)
  private String username ;
  
  @Basic
  @Column (name = "USER_PASSWORD" , columnDefinition = "NVARCHAR2(32)" , nullable = false , unique = true)
  private String  password ;
  
  @Basic
  @Column (name = "EMAIL" , columnDefinition = "NVARCHAR2(40)" , nullable = false)
  private String email;
  
  
  @Basic
  @Column (name = "SEX" , columnDefinition = "NVARCHAR2(20)")
  private String sex ;
  
  //--------------------------------------------------------
  
  public Person() { }
  
  public Person(String username, String password, String email, String sex, String userPic) {
      this.username = username;
      this.password = password;
      this.email = email;
      this.sex = sex;
      this.userPic = userPic;
  }
  public Person(String username, String password, String email ,String sex, String userPic,List&lt;Pictures&gt; picturesList ) {
      this.picturesList = picturesList;
      this.sex = sex;
      this.userPic = userPic;
      this.email = email;
      this.password = password;
      this.username = username;
  }
  
  //--------------------------------------------------------
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  public void setUserPic(String userPic) {
      this.userPic = userPic;
  }
  
  public void setSex(String sex) {
      this.sex = sex;
  }
  
  public void setuId(long uId) {this.uId = uId;}
  
  //--------------------------------------------------------
  
  public String getUsername() {
      return username;
  }
  
  public String getPassword() {
      return password;
  }
  
  public String getUserPic() {
      return userPic;
  }
  
  public String getEmail() {
      return email;
  }
  
  public String getSex() {
      return sex;
  }
  
  public long getuId() {return uId;}
  
  }
  }
  </code></pre>
  
  <p>persistence.xml :</p>
  
  <pre><code>&lt;persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
  
          &lt;!--&lt;property name="hibernate.transaction.flush_before_completion" value="true"/&gt;--&gt;
          &lt;!--&lt;property name="hibernate.format_sql" value="true"/&gt;--&gt;
  
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/&gt;
          &lt;property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/&gt;
          &lt;property name="hibernate.connection.username" value="midas"/&gt;
          &lt;property name="hibernate.connection.password" value="midas123"/&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/&gt;
          &lt;!--&lt;property name="hibernate.hbm2ddl.auto" value="create-drop"/&gt;--&gt;
          &lt;property name="show_sql" value="true"&gt;&lt;/property&gt;
         &lt;!-- &lt;property name="hibernate.globally_quoted_identifiers" value="true"/&gt;--&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>In some cases it was said that the problem was loss <code>javax.persistence.jar</code> .
  I add new <code>javax.persistence.jar</code> to my libraries but the problem was not resolved .</p>
  
  <p>I use :</p>
  
  <p><code>tomcat 8</code> 
  <code>JDK 1.8.0-172</code>
   <code>oracle 11g</code> <code>IntellyJ Idea</code> </p>
  
  <p>I used the following libraries : </p>
  
  <p>1)hibernate-enverc-4.2.0.final</p>
  
  <p>2)hibernate-jpa-2.0-api-1.0.1-final.jar</p>
  
  <p>3)tomcat library</p>
  
  <p>project Structure :</p>
  
  <p>src --> controller  --> Manager.java</p>
  
  <p>src --> model --> bl --> personManager.java</p>
  
  <p>src --> entity --> person.java </p>
  
  <p>src --> util --> JPAProvider.java</p>
  
  <p>src --> META-INF --> persistence.xml</p>
  
  <p>web --> views --> ...</p>
  
  <p>web --> WEB-INF --> lib</p>
  
  <p>web --> WEB-INF --> web.xml</p>
  
  <p>How can I fix this error?</p>