2014-10-01 85 views
0

我是hibernate框架的新手。我做了一個示例項目來測試休眠。我建立了這個項目。但是當我運行它,我得到這個錯誤休眠配置文件錯誤

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.AnnotationConfiguration.configure(AnnotationConfiguration.java:972) 
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:69) 
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414) 
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:966) 

的hibernate.cfg.xml文件,我把該項目的主要包。

<?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
    <hibernate-configuration> 

      <session-factory> 
       <property name="hibernate.dialect"> 
      org.hibernate.dialect.DerbyDialect 
       </property> 
       <property name="current_session_context_class">thread</property> 
       <property name="show_sql">true</property> 
       <property name="connection.pool_size">2</property> 
       <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 
     <!--<property name="htm2ddl.auto">create</property>--> 
       <property name="hibernate.connection.driver_class"> 
      org.apache.derby.jdbc.ClientDriver 
       </property> 

     <!-- Assume test is the database name --> 
       <property name="hibernate.connection.url"> 
      jdbc:derby://localhost:1527/NetworkDB 
       </property> 
       <property name="hibernate.connection.username"> 

       </property> 
       <property name="hibernate.connection.password"> 

       </property> 

     <!-- List of XML mapping files --> 
     <!-- <mapping resource="Employee.hbm.xml"/>--> 

      </session-factory> 

    </hibernate-configuration> 

我使用NetBeans 7.0

回答

1

按照DTD,<hibernate-configuration>應該有一個單一的<session-factory>,但你已經宣佈它的兩倍。

關於第二個錯誤:

org.hibernate.HibernateException: /hibernate.cfg.xml not found 

休眠查找在classpath的根目錄的配置文件,所以請檢查您是否已經把這個文件在你的classpath的根。

所以一旦你建立你的項目hibernate.cfg.xml文件應該在類目錄。

+0

我刪除了一個<會話工廠>節點,但仍然收到此錯誤 – 2014-10-01 06:14:37

+0

烏斯曼,你得到不同的錯誤或同樣的錯誤? – Chaitanya 2014-10-01 06:22:45

+0

當我編輯你所說的話時,錯誤是一樣的。我也在文檔的頂部添加 2014-10-01 06:24:39

1

添加在你的XML的第一線以下:

<?xml version="1.0" encoding="UTF-8"?> 
+0

現在它是一個不同的問題哥們,你以前的問題已經解決了。你在哪裏放置你的** cfg **文件? – Imran 2014-10-01 06:24:31

+0

什麼是hbm文件? – 2014-10-01 06:25:56

+0

爲什麼你對我的答案標記爲否定?請給我一個理由。 – Imran 2014-10-01 06:27:10