2013-07-23 197 views
2

我試圖編譯我的項目,但編譯器一直給錯誤,他無法找到我的資源文件,所以他無法編譯Hibernate映射無法找到資源

jul 23, 2013 1:29:24 PM org.hibernate.cfg.Configuration addResource 
INFO: HHH000221: Reading mappings from resource: src/main/resources/Movies.hbm.xml 
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: src/main/resources/Movies.hbm.xml not found 
Exception in thread "main" java.lang.ExceptionInInitializerError 
    at com.hp.videotheek.HibernateUtil.<clinit>(HibernateUtil.java:17) 
    at com.hp.videotheek.App.main(App.java:12) 
Caused by: org.hibernate.MappingNotFoundException: resource: src/main/resources/Movies.hbm.xml not found 
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:738) 
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2167) 
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2139) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2119) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2072) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1987) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1966) 
    at com.hp.videotheek.HibernateUtil.<clinit>(HibernateUtil.java:13) 
    ... 1 more 

休眠。 cfg.xml文件,在這裏,他無法找到映射資源,但它是在正確的地方

<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 

    <session-factory> 

     <!-- Database connection settings --> 
     <property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property> 
     <property name="connection.driver_class">org.postgresql.Driver</property> 
     <property name="connection.username">postgres</property> 
     <property name="connection.password">****</property> 
     <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property> 

     <!-- SQL dialect --> 
     <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 

     <!-- Enable Hibernate's automatic session context management --> 
     <property name="current_session_context_class">thread</property> 

     <!-- Drop and re-create the database schema on startup --> 
     <property name="hbm2ddl.auto">create</property> 

     <mapping resource="src/main/resources/Movies.hbm.xml"/> 

    </session-factory> 

</hibernate-configuration> 

Movies.hbm.xml

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping package="com.hp.videotheek"> 
    <class name="Movies" table="movies"> 
     <id name="movie_id" column="movie_id"> 
      <generator class="increment"/> 
     </id> 
     <property name="movie_name" type="string" column="movie_name"/> 
    </class> 
</hibernate-mapping> 

我n您可以看到我如何設定我的映射和屏幕截圖,其中的文件是在我的我的項目

enter image description here

+0

只是檢查您的類路徑開始的地方,是它src文件夾?從這一點開始你的映射資源屬性值。 – Jayesh

+0

編譯器無法在兩個casses中找到資源 – stevedc

回答

6

我固定我自己的問題,而不是給予擁抱網址我只是在映射給

<mapping resource="Movies.hbm.xml"/> 

所以,現在,他只是看起來在同一地圖的hibernate.cfg.xml文件,他會發現它立刻