2016-05-03 14 views
0

私はmysqlデータベースに接続されているプロジェクトを持っています。 私はそれは私にエラーを与えてメインクラスを実行すると:hibernate.xmlが見つかりませんでしたintellij

Failed to create sessionFactory object.org.hibernate.HibernateException: /hibernate.cfg.xml not found 
Exception in thread "main" java.lang.ExceptionInInitializerError 
at repository.Repository.<init>(Repository.java:24) 
at repository.FacultyRepository.<init>(FacultyRepository.java:20) 
at main.main(main.java:15) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found 
at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173) 
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2005) 
at org.hibernate.cfg.Configuration.configure(Configuration.java:1986) 
at org.hibernate.cfg.Configuration.configure(Configuration.java:1966) 
at repository.Repository.<init>(Repository.java:19) 
... 7 more 

を私は他の回答を読んでいると、次のように私のconfigure.xmlはSRC /資源である:

また

enter image description here

、などをあなたはprintscreenで見ることができます、私は私のファイルの休止状態で2つのエラーがあります。 誰かが私に何かを教えてくれる?

答えて

0

メインレベルのリソースフォルダからhibernate.cfg.xmlを外したとします。また、あなたのライブラリが正常であることを確認する必要があります。 ない場合、あなたがのIntelliJアイデアで作業している場合は、メインの\ javaの\ SRCの下に「リソース」という名前のフォルダを作成し、別のパス

sessionFactory = new AnnotationConfiguration() 
.configure("resources/hibernate.cfg.xml").buildSessionFactory(); 
+0

は罰金があります動作するはずです。私はそれが固定されたとそこに押して、それはインターネットからライブラリをダウンロードし、すべてが良かったということです。 –

+0

私は解決しました。私はファイルをメインレベルに置いた。ありがとう –

0

を指定する必要があります。プロジェクトのモジュール設定を開き、左から "モジュール"を選択し、 "ソース"タブで新しく作成した "リソース"フォルダを選択し、 "リソース"としてマークします。 enter image description here

これは

Configuration con = new Configuration().configure("hibernate.cfg.xml"); 
関連する問題