gpt4 book ai didi

java - Hibernate配置文件错误

转载 作者:行者123 更新时间:2023-12-02 05:24:59 24 4
gpt4 key购买 nike

我是 hibernate 框架的新手。我做了一个示例项目只是为了测试 hibernate 。我建立了该项目。但是当我运行它时,我收到了这个错误

org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:972)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:69)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:966)

我放入项目主包中的 Hibernate.cfg.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.DerbyDialect
</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<property name="connection.pool_size">2</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!--<property name="htm2ddl.auto">create</property>-->
<property name="hibernate.connection.driver_class">
org.apache.derby.jdbc.ClientDriver
</property>

<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:derby://localhost:1527/NetworkDB
</property>
<property name="hibernate.connection.username">

</property>
<property name="hibernate.connection.password">

</property>

<!-- List of XML mapping files -->
<!-- <mapping resource="Employee.hbm.xml"/>-->

</session-factory>

</hibernate-configuration>

我使用的是netbeans 7.0

最佳答案

根据 DTD,<hibernate-configuration>应该有一个 <session-factory>但你已经声明了两次。

关于第二个错误:

org.hibernate.HibernateException: /hibernate.cfg.xml not found

Hibernate 在类路径的根目录中查找配置文件,因此请检查是否已将此文件放置在类路径的根目录中。

因此,一旦您构建了项目,hibernate.cfg.xml文件应该位于类目录中。

关于java - Hibernate配置文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com