2013-03-03 77 views
-2

我在动态webproject中使用JPA项目作为jar。javax.persistence.Persistence - 动态web项目中的ClassNotFoundException

在我的项目中的某一时刻,我收到了抛出java.lang.ClassNotFoundException:javax.persistence.Persistence错误。

enter image description here

operation = RepositoryFactory.getRepositoryFactory() 
     .getUserRepository().add(feedbackverantwoordelijke); 

public boolean add(User user) { 
    EntityManagerFactory emf = HibernateRepositoryFactory 
      .getEntityManagerFactory(); 
    EntityManager em = emf.createEntityManager(); 
    EntityTransaction tx = em.getTransaction(); 
    tx.begin(); 

    User tempUser = null; 
    try { 
     // checking if the entity is already in the repository 
     if (user.getId() != null) { 
      tempUser = em.find(User.class, user.getId()); 
      //delete 
      System.out.println(user.getId()); 
      // 
     } 
     // if no persist the entity 
     if (tempUser == null) { 
      em.persist(user); 
     } else { 
      // if so, get the differences and persist them 
      tempUser.setPassword(user.getPassword()); 
      tempUser.setUserName(user.getUserName()); 
      tempUser = em.merge(user); 
     } 
    } catch (Exception e) { 
     logging.error("Deze melding trad op bij het toevoegen van een user" 
       + " :" + e); 
    } 
    tx.commit(); 
    em.close(); 
    emf.close(); 
    return true; 
} 

注:Feedbackverantwoordelijke扩展用户

这完美的作品从我的JPA项目中。但是当我在动态web项目中从JPA jar中调用此函数时,我收到错误消息。

看来我在我的动态webproject中运行时缺少一个jar('s)。通常所有的jar都在我的JPA项目中,我可以在我的JPA项目中执行所有的CRUD操作?

我必须在我的Dynamic Web项目中加载一些jar吗?如果是这样,我必须将它们放在我的WEB-INF/lib文件夹中吗?

我也在我的JPA项目和Web邮件jar中使用joda-time jar。我必须将这些罐子放在我的动态web项目中。

Thx for reply's

+0

你能提供任何代码去与此? – christopher 2013-03-03 19:03:16

+0

Thx为downvote。我可以提供代码,但使用它是没有用的。当我尝试使用存储库函数检查数据库中的某些内容时,我收到错误消息。如上所述,这在JPA项目中运行良好。但是从我的动态web项目中将JPA项目作为jar包,我不能。如上所述,我认为我错过了一个jar,但通常所有jar都在我的JPA项目中! – 2013-03-03 19:08:04

+1

您必须在运行时提供JPA实现,不同应用程序服务器之间的差异如何。顺便说一句:“??”与“和“?”? – esej 2013-03-03 19:50:40

回答

1

修正了它。我需要将hibernate jar和其他外部jar添加到我的动态webproject的WEB-INF/lib文件夹中。现在我可以坚持数据库。