Hibernate - Initial SessionFactory creation failed
- From: "Regi" <rslomski@xxxxxxxxx>
- Date: 29 Mar 2007 01:44:38 -0700
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
.
- Prev by Date: Re: Hibernate305: delete query fails with "must begin with SELECT or FROM"
- Next by Date: How to increase the speed of searching in a large database?
- Previous by thread: Hibernate305: delete query fails with "must begin with SELECT or FROM"
- Next by thread: How to increase the speed of searching in a large database?
- Index(es):
Relevant Pages
|
|