title: Unable to create session factory in Hibernate
body: <p>I am learning hibernate 4 but got stuck in creation of <strong>Session Factory</strong>
  and please review my code and help me to find out the cause of problem as i am using hibernate-core 5.0.6, MySQL connector 5.0.8, log4j 1.2.17,jta jar,dom4j,and jboss-logging jar and this is my code for session factory</p>
  
  <pre><code>class HibernateUtill 
  {
  
      private static final SessionFactory sessionFactory;
          static {
              try {
                  Logger logger = Logger.getLogger("Mylogger");
                  logger.info("Trying to create a test connection with database");
                  Configuration configuration = new Configuration().configure();
                  configuration.configure();
                  StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration
                          .getProperties());
                  sessionFactory = configuration.buildSessionFactory(builder.build());
              } catch (Throwable ex) {
                  System.out.println("SessionFactory creation failed with error" + ex);
                  throw new ExceptionInInitializerError(ex);
              }
  
          }
  
          public static SessionFactory getSessionFactory() {
              return sessionFactory;
  
          }
  
          public static void shutDown() {
              sessionFactory.close();
          }
  }
  </code></pre>
  
  <p>and the error I'm getting is :</p>
  
  <pre><code> log4j:WARN No appenders could be found for logger (org.jboss.logging).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  SessionFactory creation failed with errororg.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at com.commonClasses.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:19)
      at com.java.save.SavingObject.savingObject(SavingObject.java:13)
      at com.java.save.SavingObject.main(SavingObject.java:31)
  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:259)
      at com.commonClasses.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:12)
      ... 2 more
  </code></pre>
  
  <p>or in simple terms <strong>errororg.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource</strong></p>
  
  <p>The things I know is the error is due to log4j and I placed log4j.properties in src folder and the code for the property file is </p>
  
  <pre><code># Root logger option
  log4j.rootlogger=INFO,stdout
  
  #Direct log messages to stdout
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  
  #log JDBC bind parameter runtime arguments
  log4j.logger.org.hibernate.type=trace
  </code></pre>
  
  <p>please help me to solve this error and cause of this error too.
  any help is appreciated,
  Thanks.</p>