2013-03-03 38 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文件夾中。現在我可以堅持數據庫。