Maven project using Hibernate. When starting, errors occur:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Failed to create sessionFactory object.org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml] Exception in thread "main" java.lang.ExceptionInInitializerError at com.art.ManageEmployee.main(ManageEmployee.java:20) 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:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Caused by: 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 com.art.ManageEmployee.main(ManageEmployee.java:16) ... 5 more 

What is this log4j2 file? Why is it? Why does it cause errors?

File hibernate.cfg.xml:

 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <!-- Assume test is the database name --> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/test </property> <property name="hibernate.connection.username"> root </property> <property name="hibernate.connection.password"> root </property> <!-- List of XML mapping files --> <mapping resource="com/art/Employee.hbm.xml"/> </session-factory> 

  • one
    You have an error Could not locate cfg.xml resource [hibernate.cfg.xml] . Here is the problem, not in the configs of the logger. - Vartlok
  • @Vartlok, added hibernate.cfg.xml, what's wrong with it? - bsuart
  • one
    Judging by the error, he lies someone is not there. - Vartlok
  • @Vartlok, and where should it lie? - bsuart
  • 2
    usually src/main/resources stackoverflow.com/a/18736719/1646082 - Vartlok

1 answer 1

Solution: the file should be in src/main/resources .

Detailed explanation: https://stackoverflow.com/a/18736719/1646082

  • Maybe translate the answer entirely into Russian? Just links are not enough for a good answer. :) - Nick Volynkin