0

I can’t connect my config file, it gives an error, I tried these methods org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [/HibernateTest/src/hibernate.cfg.xml] but they don’t work
This is my code

SessionFactory sessionFactory = new Configuration()
            .configure("./hibernate.cfg.xml")
            .addAnnotatedClass(Employee.class)
            .buildSessionFactory();

    try {
        Session session = sessionFactory.getCurrentSession();
        Employee employee = new Employee("Marsel", "Charginov", "IT", 500);
        session.beginTransaction();
        session.save(employee);
        session.getTransaction().commit();
    }finally {
        sessionFactory.close();
    }

This is my error

февр. 21, 2022 11:07:56 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.6.3.Final
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could         
not locate cfg.xml resource [./hibernate.cfg.xml]

This is my file structure

  • src
    • main
      • java
        • hibernate
          • Main.java
            • entity
              • Employee.java
    • resources
      • hibernate.cfg.xml
Hankie-2
  • 5
  • 3

1 Answers1

0

Hibernate xml file should be inside src . Looks like it is inside main package

If it is EE, always put it into WEB-INF/classes directory (compiled files are stored there).

ilia
  • 98
  • 1
  • 8