Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hibernate tutorial problem

3,620 views
Skip to first unread message

willia...@gmail.com

unread,
Sep 15, 2008, 7:18:43 PM9/15/08
to
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

Nikolai.Smirnov

unread,
Sep 16, 2008, 3:54:03 AM9/16/08
to

I have the save problem...

Christos

unread,
Sep 16, 2008, 6:18:36 AM9/16/08
to
On Sep 16, 8:54 am, "Nikolai.Smirnov" <Nikolai.Smir...@gmail.com>
wrote:

> On 16 ÓÅÎÔ, 03:18, william.w...@gmail.com wrote:
>
>
>
> > 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...

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

jver...@gmail.com

unread,
Sep 16, 2008, 9:03:20 AM9/16/08
to
Yes, this solution works for this problem.

Thanks Christos,

J.

jglo...@gmail.com

unread,
Sep 16, 2008, 10:59:29 AM9/16/08
to

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

luigi.br...@gmail.com

unread,
Sep 16, 2008, 11:49:37 AM9/16/08
to

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

MicMin

unread,
Oct 27, 2008, 6:55:19 PM10/27/08
to
This works for me ! Thank you !!

Mike...@gmail.com

unread,
Nov 5, 2008, 9:15:37 PM11/5/08
to
Man, it works for me too.

Thanks,

xiaoxi...@gmail.com

unread,
Nov 19, 2008, 11:54:07 AM11/19/08
to
On Nov 5, 9:15 pm, Mike....@gmail.com wrote:
> Man, it works for me too.
>
> Thanks,

works for me as well. thanks!

0 new messages