0

我遵循了本教程: 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> 
4

1 回答 1

0

将映射文件移动到 src/main/resources。只有 .java 文件属于 src/main/java。

github 上有一个示例项目,展示了如何从 hibernate.cfg.xml 中正确引用 XML 映射文件。请参考https://github.com/zzantozz/testbed/tree/master/hibernate-with-xml-mappings

于 2013-10-13T04:54:09.520 回答