Could not locate cfg.xml resource [hibernate.cfg.xml]

1

Good people ... I just registered in Stackoverflow, since I have the following problem: I am trying to insert a record in a MySql Database using MAVEN and HIBERNATE .. As an Operating System I have Ubuntu Mate 16.04.3 LTS. When running my code, ECLIPSE NEON .. tells me that it can not locate the file hibernate.cfg.xml . I use the following class to create the session:

public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {           
            StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
            Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build();
            return metadata.getSessionFactoryBuilder().build();

        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("*** Creación de SessionFactory falló." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

The error ECLIPSE shows me:

  

Aug 01, 2017 7:57:20 PM org.hibernate.Version logVersion INFO:   HHH000412: Hibernate Core {5.2.1.Final} Aug 01, 2017 7:57:20 PM   org.hibernate.cfg.Environment INFO: HHH000206:   hibernate.properties not found Aug 01, 2017 7:57:20 PM   org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021:   Bytecode provider name: javassist   *** Creation of SessionFactory failed.org.hibernate.internal.util.config.ConfigurationException: Could   not locate cfg.xml resource [hibernate.cfg.xml] Exception in thread   "main" java.lang.ExceptionInInitializerError at   com.novellius.util.HibernateUtil.buildSessionFactory (HibernateUtil.java:31)     at com.novellius.util.HibernateUtil. (HibernateUtil.java:11)     at com.novellius.test.Test.main (Test.java:13) 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   com.novellius.util.HibernateUtil.buildSessionFactory (HibernateUtil.java:23)     ... 2 more

I already appreciate any help. As a last question I want to clarify that the file that ECLIPSE can not find: hibernate.cfg.xml I have it in the SRC folder of the project.

    
asked by Luis Z 02.08.2017 в 01:19
source

0 answers