Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / April 2007

Tip: Looking for answers? Try searching our database.

Hibernate - Initial SessionFactory creation failed

Thread view: 
Regi - 29 Mar 2007 09:44 GMT
Hello!
I have little problem with a basic hibernate configuration.
I'll be very grateful if someone could help me.

Files:

Event.java
------------------------------
package events;

public class Event {

    public Long id;
    public String nazwa_klienta;

    public Event() {}

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNazwa_klienta() {
        return nazwa_klienta;
    }

    public void setNazwa_klienta(String nazwa_klienta) {
        this.nazwa_klienta = nazwa_klienta;
    }

}

Event.hbm.xml
----------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="events">
 <class name="Event" table="Klienci">
     <id name="id" column="id">
        <generator class="sequence">
            <param name="sequence">klienci_id_seq</param>
        </generator>
    </id>
    <property name="nazwa_klienta"/>
 </class>
</hibernate-mapping>

Hibernate.cfg.xml
--------------------------------
<?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">org.postgresql.Driver</
property>
    <property name="connection.url">jdbc:postgresql://localhost/Dane_ref</
property>
    <property name="connection.username">postgres</property>
    <property name="connection.password">mykmyk</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</
property>
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
    <!-- Disable the second-level cache -->
    <property
name="cache.provider_class">org.hibernate.cache.NoCacheProvider</
property>
    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    <!-- Use the Hibernate built-in pool for tests. -->
    <property name="connection.pool_size">1</property>
    <property
name="cache.provider_class">org.hibernate.cache.NoCacheProvider</
property>
    <property name="cache.use_query_cache">false</property>
    <property name="cache.use_minimal_puts">false</property>
    <property name="max_fetch_depth">3</property>
    <!-- Print SQL to stdout. -->
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <!-- Drop and then re-create schema on SessionFactory build, for
testing. -->
    <!-- Bind the getCurrentSession() method to the thread (don't use for
EJBs) -->
    <property name="current_session_context_class">thread</property>
    <!-- Batch inserts are currently broken, no idea why... -->
    <property name="jdbc.batch_size">0</property>

    <mapping resource="events/Event.hbm.xml" />

</session-factory>
</hibernate-configuration>

EventManager.java
-------------------------------
package events;

import org.hibernate.Session;

import util.HibernateUtil;

public class EventManager {

    private static Session session;
   public Session getSession(){
       return EventManager.session;
   }

    public void polacz() {
        session = HibernateUtil.getSessionFactory().openSession();
    }

}

Start.java
---------------
package events;

public class Start {

    private EventManager mgr = null;
    boolean tak;

    public Start(){
        mgr = new EventManager();
        //mgr.polacz();
    }
    public static void main(String[] args) {
        Start start = new Start();

        start.mgr.polacz();
    }
}

HibernateUtil.java
----------------------------
package util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.*;

public class HibernateUtil {
    private static final SessionFactory sessionFactory;
        static {
            try {

                //Create the SessionFactory from hibernate.cfg.xml

                Configuration cfg = new Configuration();
                cfg.configure("hibernate.cfg.xml");

                //cfg.setProperty("hibernate.connection.password", "grasz");

                sessionFactory =cfg.buildSessionFactory();

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

And I have follows errors:
----------------------------------------------

*************************Initial SessionFactory creation
failed.java.lang.ExceptionInInitializerError
Exception in thread "main" java.lang.ExceptionInInitializerError
    at util.HibernateUtil.<clinit>(HibernateUtil.java:24)
    at events.EventManager.polacz(EventManager.java:15)
    at events.Start.main(Start.java:15)
Caused by: java.lang.ExceptionInInitializerError
    at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
    ... 2 more
Caused by: org.apache.commons.logging.LogConfigurationException:
java.lang.NullPointerException
    at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:
558)
    at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:
355)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:390)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:116)
    ... 3 more
Caused by: java.lang.NullPointerException
    at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:
543)
    ... 6 more

Thanks for any advice
Regi
made.adi@gmail.com - 11 Apr 2007 09:53 GMT
> Hello!
> I have little problem with a basic hibernate configuration.
[quoted text clipped - 204 lines]
> Thanks for any advice
> Regi

Maybe you should copy all Jar files in hibernate root folder \lib to
your \lib working folder. That works for me.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.