Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate Session Factory issue
    primarykey
    data
    text
    <p>I am using hibernate 4 for building an application. While running the application I am getting the following error.</p> <blockquote> <p>Failed to create sessionFactory object.java.lang.NoSuchFieldError: TRACE Exception in thread "main" java.lang.NullPointerException</p> </blockquote> <p>My code snippet is,</p> <pre><code>try{ session = new DBConnection().getSession(); tx= session.beginTransaction(); ........ ........ }catch(HibernateException ex) { if (tx!=null) tx.rollback(); ex.printStackTrace(); session.close(); DBConnection.close(); } catch(Exception ex) { ex.printStackTrace(); session.close(); } finally{ session.close(); // The error is shown in this line while run time DBConnection.close(); } </code></pre> <p>DBConnection.java</p> <pre><code>public DBConnection() { try { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); factory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { System.err.println("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex); } } public Session getSession() { return factory.openSession(); } // Call this during shutdown public static void close() { factory.close(); } </code></pre> <p>My configuration file is :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.dialect"&gt; org.hibernate.dialect.MySQLDialect &lt;/property&gt; &lt;property name="hibernate.connection.driver_class"&gt; com.mysql.jdbc.Driver &lt;/property&gt; &lt;!-- Assume test is the database name --&gt; &lt;property name="hibernate.connection.url"&gt; jdbc:mysql://localhost:3306/test &lt;/property&gt; &lt;property name="hibernate.connection.username"&gt; root &lt;/property&gt; &lt;property name="hibernate.connection.password"&gt; test &lt;/property&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;property name="format_sql"&gt;true&lt;/property&gt; &lt;property name="use_sql_comments"&gt;false&lt;/property&gt; &lt;property name="hibernate.connection.pool_size"&gt;40&lt;/property&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>Please guide me what is wrong with the code or any jar file?</p> <p>**</p> <blockquote> <p>Answer: The log4j is the cause of this issue. I removed the Log4j and added log4j-1.2.16.jar. It gets fixed. Thanks!</p> </blockquote> <p>**</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload