Hibernate tutorial problem

W

william.wied

I am getting the following error when I try to run the Hibernate
tutorial code below:

HERE1
HERE2
Initial SessionFactory creation failed.java.lang.NoSuchFieldError:
name
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at events.EventManager.createAndStoreEvent(EventManager.java:50)
at events.EventManager.main(EventManager.java:18)
Caused by: java.lang.NoSuchFieldError: name
at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:
75)
at
org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:
75)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 2 more


Hibernate.java:

package util;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new
Configuration().configure().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;
}

}



EventManager.java:

package events;
import org.hibernate.Session;
import java.util.List;
import java.util.Date;
import util.HibernateUtil;
public class EventManager {

public static void main(String[] args) {
EventManager mgr = new EventManager();

System.out.println("HERE1");
if (args[0].equals("store")) {
System.out.println("HERE2");
mgr.createAndStoreEvent("My Event", new Date());
System.out.println("HERE3");
}
}



I am running this code in Eclipse and was originally thinking it was a
problem with the log4j.properties file, but I can't figure out what
the problem is.

Your help is appreciated.

Bill
 
N

Nikolai.Smirnov

I am getting the following error when I try to run the Hibernate
tutorial code below:

HERE1
HERE2
Initial SessionFactory creation failed.java.lang.NoSuchFieldError:
name
Exception in thread "main" java.lang.ExceptionInInitializerError
š š š š at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
š š š š at events.EventManager.createAndStoreEvent(EventManager.java:50)
š š š š at events.EventManager.main(EventManager.java:18)
Caused by: java.lang.NoSuchFieldError: name
š š š š at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:
75)
š š š š at
org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:
75)
š š š š at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
š š š š at org.hibernate.cfg.Configuration.<clinit>(Configuration..java:151)
š š š š at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
š š š š ... 2 more

Hibernate.java:

package util;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {

š š private static final SessionFactory sessionFactory;

š š static {
š š š š try {
š š š š š š // Create the SessionFactory from hibernate.cfg.xml
š š š š š š sessionFactory = new
Configuration().configure().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;
š š }

}

EventManager.java:

package events;
import org.hibernate.Session;
import java.util.List;
import java.util.Date;
import util.HibernateUtil;
public class EventManager {

š š public static void main(String[] args) {
š š š š EventManager mgr = new EventManager();

š š š š System.out.println("HERE1");
š š š š if (args[0].equals("store")) {
š š š š š š š š System.out.println("HERE2");
š š š š š š mgr.createAndStoreEvent("My Event", new Date());
š š š š š š System.out.println("HERE3");
š š š š }

}

I am running this code in Eclipse and was originally thinking it was a
problem with the log4j.properties file, but I can't figure out what
the problem is.

Your help is appreciated.

Bill

I have the save problem...
 
C

Christos

I am getting the following error when I try to run the Hibernate
tutorial code below:
HERE1
HERE2
Initial SessionFactory creation failed.java.lang.NoSuchFieldError:
name
Exception in thread "main" java.lang.ExceptionInInitializerError
š š š š at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
š š š š at events.EventManager.createAndStoreEvent(EventManager..java:50)
š š š š at events.EventManager.main(EventManager.java:18)
Caused by: java.lang.NoSuchFieldError: name
š š š š at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:
75)
š š š š at
org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:
75)
š š š š at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
š š š š at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
š š š š at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
š š š š ... 2 more

package util;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
š š private static final SessionFactory sessionFactory;
š š static {
š š š š try {
š š š š š š // Create the SessionFactory from hibernate.cfg..xml
š š š š š š sessionFactory = new
Configuration().configure().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;
š š }


package events;
import org.hibernate.Session;
import java.util.List;
import java.util.Date;
import util.HibernateUtil;
public class EventManager {
š š public static void main(String[] args) {
š š š š EventManager mgr = new EventManager();
š š š š System.out.println("HERE1");
š š š š if (args[0].equals("store")) {
š š š š š š š š System.out.println("HERE2");
š š š š š š mgr.createAndStoreEvent("My Event", new Date());
š š š š š š System.out.println("HERE3");
š š š š }

I am running this code in Eclipse and was originally thinking it was a
problem with the log4j.properties file, but I can't figure out what
the problem is.
Your help is appreciated.

I have the save problem...

I was having the same problem and I solved it by downloading an older
version of slf4j.


the version of slf4j-api shipped with hibernate is 1.5.2 (lib/common/
slf4j-1.5.2.jar)

I downloaded the same version of slf4j from here: http://www.slf4j.org/dist/
and the problem is gone.

Regards,
Christos
 
J

jglotain

Yes, this solution works for this problem.

Thanks Christos,

J.

this solution stil doesn's work for me ...
I have :


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for
further details.
Initial SessionFactory creation failed.
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at annuaire.test.TestHibernate.main(TestHibernate.java:14)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/
StaticLoggerBinder
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 1 more

Julien
 
L

luigi.brandolini

this solution stil doesn's work for me ...
I have :

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderfor
further details.
Initial SessionFactory creation failed.
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Exception in thread "main" java.lang.ExceptionInInitializerError
        at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
        at annuaire.test.TestHibernate.main(TestHibernate.java:14)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/
StaticLoggerBinder
        at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
        at org.hibernate.cfg.Configuration.<clinit>(Configuration..java:151)
        at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
        ... 1 more

Julien

Hi,
i had the same problem,but i worked it out adding the "slf4j-
jdk14-1.5.2.jar" in the project's classpath. The missing class is
inside.

Regards,

Luis
 
M

MicMin

This works for me ! Thank you !!

Hi,
i had the same problem,but i worked it out adding the "slf4j-
jdk14-1.5.2.jar" in the project's classpath. The missing class is
inside.

Regards,

Luis
 
Joined
Nov 18, 2008
Messages
1
Reaction score
0
I had this problem before:
I'm using Hibernate-core 3.3.1.GA, which requires slf4j 1.5.2, However I was using the latest slf4j 1.5.5 when the problem occurred.
when I used the correct version (1.5.2), every thing ran smoothly afterwards.
 
Joined
Feb 10, 2009
Messages
1
Reaction score
0
I Need Assitance

AS MUCH AS I HAVE SEEN YOU SOLVE A DIFFERENT PROBLEM I WOULD WANT ENLIGHTENMENT ON THIS ONE ....AFTER RUNING THE ANT -Daction=store i get the following problems.
ofcos i know its a library problem but i dnt know where to get it from.
any help will be appreciated.
thanks
Laa

compile:
[javac] Compiling 2 source files to /home/laa/hibernate/bin
[javac] /home/laa/hibernate/src/EventManager.java:2: package org.hibernate does not exist
[javac] import org.hibernate.Session;
[javac] ^
[javac] /home/laa/hibernate/src/util/HibernateUtil.java:3: package org.hibernate does not exist
[javac] import org.hibernate.*;
[javac] ^
[javac] /home/laa/hibernate/src/util/HibernateUtil.java:4: package org.hibernate.cfg does not exist
[javac] import org.hibernate.cfg.*;
[javac] ^
[javac] /home/laa/hibernate/src/util/HibernateUtil.java:8: cannot find symbol
[javac] symbol : class SessionFactory
[javac] location: class util.HibernateUtil
[javac] private static final SessionFactory sessionFactory;
[javac] ^
[javac] /home/laa/hibernate/src/util/HibernateUtil.java:21: cannot find symbol
[javac] symbol : class SessionFactory
[javac] location: class util.HibernateUtil
[javac] public static SessionFactory getSessionFactory() {
[javac] ^
[javac] /home/laa/hibernate/src/EventManager.java:22: cannot find symbol
[javac] symbol : class Session
[javac] location: class events.EventManager
[javac] Session session = HibernateUtil.getSessionFactory().getCurrentSession();
[javac] ^
[javac] /home/laa/hibernate/src/EventManager.java:26: cannot access events.Event
[javac] bad class file: /home/laa/hibernate/bin/events/Event.class
[javac] class file contains wrong class: org.hibernate.tutorial.domain.Event
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
[javac] Event theEvent = new Event();
[javac] ^
[javac] 7 errors
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top