私はHibernateの使い方を学ぼうとしています。私は、チュートリアル、以下の小規模なプロジェクトを作成しましたが、私はそれを実行しようとすると、それは、この例外がスローされます。 http://pastebin.com/pu2FnmmThibernate.cfg.xmlが見つかりませんでした
はhibernate.cfg.xml
を見つけることができない私には思えます。私はこれがおそらく以前に尋ねられていることを知っています。すべての解決策では、hibernate.cfg.xml
を/ srcフォルダに置かなければならないと言います。これは私がしたことですが、何らかの理由でこのエラーがポップアップし続けます。
私は関与コードを貼り付けました下:
HibernateUtil.java
package util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import model.Device;
public class HibernateUtil {
public static void main(String[] args) {
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistery = builder.build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistery);
Session session = sessionFactory.openSession();
Device device = new Device();
device.setId(4);
device.setName("Test Smart TV");
Transaction tx = session.beginTransaction();
session.save(device);
tx.commit();
System.out.println("Object saved successfully.....!!");
session.close();
sessionFactory.close();
}
}
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>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/poc</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo all executed SQL to sysout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">create</property>
<!-- Mapping file -->
<mapping resource="device.hbm.xml" />
</session-factory>
</hibernate-configuration>
を次のように私のプロジェクト構造は次のとおりです。 https://puu.sh/tl50v/31cb4b0da9.png
何か助けやアドバイスをいただければ幸いです。
こんにちは、お返事ありがとうございます。しかし、それはすでにここにあります。https://puu.sh/tl50v/31cb4b0da9.png。それとも別の意味ですか? – Jack
あなたの写真によると、 'hibernate.cfg.xml'はsrcの下にあります!!あなたのプロジェクトのsrcフォルダと同じレベルになければなりません! –