我遵循了本教程:http://manikandanmv.wordpress.com/2011/04/13/hibernate-basics-simple-example/
这是我的文件结构 http://i.stack.imgur.com/sX3nn.jpg
当我运行Java Applet时,我收到此错误
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: src/com/bookstore/bookapp.hbm.xml not found
但是,我有那个文件,你可以看到它。当我把文件放在
下workspace-windows\226project1\src\com\bookstore
即使那时我仍然面临这个错误,有人可以帮忙吗?
这是我的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">rocker123</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/com/bookstore/bookapp.hbm.xml"/>
</session-factory>
</hibernate-configuration>
答案 0 :(得分:0)
将映射文件移动到src / main / resources中。只有.java文件属于src / main / java。
github上有一个示例项目,展示了如何从hibernate.cfg.xml正确引用XML映射文件。请参阅https://github.com/zzantozz/testbed/tree/master/hibernate-with-xml-mappings