【发布时间】:2018-05-22 06:39:08
【问题描述】:
我尝试了很多方法来解决这个错误(使用 maven 项目)
- 我将 hibernate.cfg.xml 文件放在 src 文件夹中然后得到同样的错误(没有找到 hibernate.properties)
- 我将 hibernate.cfg.xml 文件放在资源文件夹中然后得到同样的错误(没有找到 hibernate.properties)
- 我把 hibernate.cfg.xml 文件放在 webapp/WEB-INF 文件夹然后得到同样的错误(没有找到 hibernate.properties)
- 我在hibernate.cfg.xml中写的所有数据库属性如下
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testdb</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">sql123</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hbm2ddl.auto">create </property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping resource="Employee-hbn.xml" />
</session-factory>
</hibernate-configuration>
May 22, 2018 2:28:38 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.3.0.Final}
May 22, 2018 2:28:38 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Could not locate cfg.xml resource [/src/main/java/hibernate.cfg.xml]
error
如果您对此有解决方案,请告诉我
提前谢谢....
【问题讨论】:
-
您已经为映射“hbm”xml 资源提供了“Employee-hbn.xml”。您可以在这里检查文件名是否正确。将文件名更改为“Employee.hbm.xml”一次。一般来说,“hibernate.cfg.xml”文件应该放在“src/main/resources”路径中
-
是的,“Employee-hbn.xml”的文件名与我放入 hbn 映射的文件名相同,“hibenate.cfg.xml”也在“src/main/resources”路径中... .
-
把文件名改成“Employee.hbm.xml”,你还需要支持hibernate的jar文件,比如antlr.jar,hibernate3.jar,和commons jars。等等。请检查所需的jar一次
-
请在映射中保持类似“com/Test/sampleproject/yourhbmfilename.hbm.xml”的路径
-
请添加错误的堆栈跟踪。你哪里有这个错误?