hibernate.cfg.xml не найден

#hibernate

#переход в спящий режим

Вопрос:

Дерево

 michael@michael:~/IdeaProjects/tulesco/tulesco$ tree
.
├── pom.xml
├── src
│   ├── hibernate.cfg.xml
│   ├── main
│   │   └── java
│   │       └── org
│   │           └── example
│   │               ├── Alien.java
│   │               └── App.java
│   └── test
│       └── java
│           └── org
│               └── example
│                   └── AppTest.java
  

Трассировка

 /usr/lib/jvm/jdk-11.0.8/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:58987,suspend=y,server=n -javaagent:/home/michael/Documents/idea-IC-202.6397.94/plugins/java/lib/rt/debugger-agent.jar -Dfile.encoding=UTF-8 -classpath /home/michael/IdeaProjects/tulesco/tulesco/target/classes:/home/michael/.m2/repository/org/hibernate/hibernate-core/4.1.6.Final/hibernate-core-4.1.6.Final.jar:/home/michael/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/home/michael/.m2/repository/org/jboss/logging/jboss-logging/3.1.0.GA/jboss-logging-3.1.0.GA.jar:/home/michael/.m2/repository/org/jboss/spec/javax/transaction/jboss-transaction-api_1.1_spec/1.0.0.Final/jboss-transaction-api_1.1_spec-1.0.0.Final.jar:/home/michael/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/michael/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.jar:/home/michael/.m2/repository/org/javassist/javassist/3.15.0-GA/javassist-3.15.0-GA.jar:/home/michael/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.1.Final/hibernate-commons-annotations-4.0.1.Final.jar:/home/michael/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar:/home/michael/Documents/idea-IC-202.6397.94/lib/idea_rt.jar org.example.App
Connected to the target VM, address: '127.0.0.1:58987', transport: 'socket'
Hello World!
Aug 27, 2020 4:37:25 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Aug 27, 2020 4:37:25 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.6.Final}
Aug 27, 2020 4:37:25 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 27, 2020 4:37:25 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 27, 2020 4:37:25 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Aug 27, 2020 4:37:25 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" 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:1949)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1930)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1910)
    at org.example.App.main(App.java:21)
Disconnected from the target VM, address: '127.0.0.1:58987', transport: 'socket'

Process finished with exit code 1
  

The hibernate.cfg.xml находится в каталоге src. В меру своих возможностей я не могу понять, почему is не обнаружен. Не могли бы вы любезно сказать мне, почему hibernate.cfg.xml не найден? И как это исправить?

введите описание изображения здесь

Ответ №1:

Он должен быть в пути к классу. В случае проектов Maven вы можете поместить его в:

 srcmainresourceshibernate.cfg.xml