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
4
  • Looks like you put your config file into the directory src/resources whereas it should be src/main/resources. Commented Feb 21, 2022 at 17:36
  • it still not working Commented Feb 21, 2022 at 17:38
  • Try hibernate.cfg.xml instead of ./hibernate.cfg.xml Commented Feb 21, 2022 at 19:43
  • it still not working Commented Feb 22, 2022 at 5:17

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.