プロジェクトルートフォルダーにhibernate.cfg.xmlファイルがあります。
私が含むアプリケーションを実行すると:
_SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
_
configure()
メソッドでクラッシュし、次のメッセージが表示されます。
Cfg.xmlリソースが見つかりませんでした[hibernate.cfg.xml]
出力:
_Jun 17, 2016 12:04:59 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
Jun 17, 2016 12:04:59 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.max_fetch_depth=5, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.connection.pool_size=5}
Jun 17, 2016 12:04:59 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.Java:53)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.Java:163)
at org.hibernate.cfg.Configuration.configure(Configuration.Java:258)
at org.hibernate.cfg.Configuration.configure(Configuration.Java:244)
at o.k.j.HibernateTest.main(HibernateTest.Java:22)
_
hibernate.cfg.xmlファイルをsrcフォルダーに移動する必要があります。
Mavenを使用してプロジェクトをビルドしている場合は、「src/main/resources」の下に「hibernate.cfg.xml」ファイルを配置します
ビルドツールとしてMavenを使用している場合は、hibernate.cfg.xml
resourcesフォルダの下。
アプリケーションにHibernate設定ファイルを参照させる手順
resourcesフォルダーを右クリックしてMark Directory Asオプションを選択し、Resources Rootをクリックします。
これらの手順はInteliJ IDEA Ultimate 14。で機能しました
Forward /を使用して、cfgファイルを転送せずに配置します/機能しません