2011-04-05 43 views
0

我正在運行使用Hibernate進行數據持久性的Web應用程序。Web項目和休眠異常

現在我創建了另一個webproject幷包含必要的jar文件等。 在獲取數據時,我得到一個異常。

Exception in thread "main" java.lang.ExceptionInInitializerError 
    at com.util.HibernateUtil.<clinit>(Unknown Source) 
    at java.lang.J9VMInternals.initializeImpl(Native Method) 
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:177) 
    at com.core.dao.OpenIncidentDao.getAllOpenIncidents(Unknown Source) 
    at Test.main(Test.java:17) 
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found 
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147) 
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1427) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1414) 
    ... 5 more 

我的其他web項目運行良好。另外hibernate.cfg.xml是在它的位置。 hibernate.cfg.xml在EarContent/hibernate.cfg.xml下

+0

是'WEB-INF /' – JoseK 2011-04-05 11:26:25

+0

中的hibernate.cfg.xml hibernate.cfg.xml位於EarContent/hibernate.cfg.xml下。 Web項目和hibernate項目都添加到EAR中。 – 2011-04-05 11:30:44

回答

0

調用我的hibernate類時出現問題。我沒有從jsp頁面調用它。這樣做的問題解決了。

在此之前,我從java class main方法調用它來測試它。

0

類路徑問題。檢查以查看哪個是您的項目根文件夾。

+0

EAR中添加了Web項目和hibernate項目。 – 2011-04-05 11:31:56

+0

然後這是一個ClassLoader問題。你在使用哪個應用服務器? – ludovicianul 2011-04-05 11:44:47

+0

我所有的hibernate類都可以訪問。當它嘗試進行會話時出現問題。 Appserver:JBoss。 – 2011-04-05 11:52:29