eclipse Hibernate映射找不到资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17809238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate mapping can't find resources
提问by stevedc
I'm trying to compile my project but the compiler keeps giving the error that he can't find my resource file and so he can't compile
我正在尝试编译我的项目,但编译器不断给出他找不到我的资源文件的错误,因此他无法编译
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
hibernate.cfg.xml file, here he can't find the mapping resources but it's on the right place
hibernate.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
电影.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>
In the screenshot you can see how I have set my mapping and where the files are in my my project
在屏幕截图中,您可以看到我如何设置映射以及文件在我的项目中的位置
回答by stevedc
I fixed my own problem instead of giving the hug url I just gave in mapping
我解决了我自己的问题,而不是给出我刚刚在映射中给出的拥抱网址
<mapping resource="Movies.hbm.xml"/>
So now he just looks in the same map as the hibernate.cfg.xml file and he will find it immediatly
所以现在他只需查看与 hibernate.cfg.xml 文件相同的地图,他就会立即找到它