Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Hibernate Annotations Error
PostPosted: Sat Nov 29, 2008 12:19 am 
Newbie

Joined: Wed Apr 23, 2008 3:36 pm
Posts: 6
Hibernate version:
hibernate-distribution-3.3.1.GA

Mapping documents
None

Code between sessionFactory.openSession() and session.close():
Code:
package com.gss.DAO;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.gss.POJOs.Student;

public class Test{
   public static void main(String args[])
     {
       Session session = null;

       try{
         SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
         session=sessionFactory.openSession();
           Student stud = new Student();
           stud.setId(1);
           stud.setName("Arul");
            session.save(stud);
           session.flush();
       }catch(Exception e){
         e.printStackTrace();
           }
      
       }
}



Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at com.gss.DAO.Test.main(Test.java:14)

Name and version of the database you are using:
Oracle 10g

The generated SQL (show_sql=true):
Don't know.

Debug level Hibernate log excerpt:
Don't know.

Hi All,

I basically have a table called STUDENT in the Oracle 10g database with ID as primary key and Name as another column and I am trying to insert into the table values using Annotations so I basically don't have a Mapping file. The DAO Class is already given above. Here's the POJO class and the config files.

Pojo:

Code:
package com.gss.POJOs;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "STUDENT")

public class Student implements Serializable {

   @Id
   @Column(name = "ID")
   Integer id;
   
   @Column(name = "NAME")
   String name;
   
   
   public Integer getId() {
      return id;
   }
   public void setId(Integer id) {
      this.id = id;
   }
   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }
   
   
}


hibernate.cfg.xml file:
Code:
<?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>
        <property name="connection.driver_class">
          oracle.jdbc.driver.OracleDriver
        </property>
        <property name="connection.url">
          jdbc:oracle:thin:@localhost:1521:XE
        </property>
                <property name="connection.username">
          System
        </property>
        <property name="connection.password">
          1234
        </property>
        <!-- Set AutoCommit to true -->
        <property name="connection.autocommit">
          true
        </property>
        <!-- SQL Dialect to use. Dialects are database specific -->
        <property name="dialect">
          org.hibernate.dialect.OracleDialect
        </property>
        <!-- Mapping files -->
        <mapping class="com.gss.POJOs.Student" />
      </session-factory>
    </hibernate-configuration>


I actually had the following error when I did not have sl4j-log4j12-1.5.6 added to my build path:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" 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 com.gss.DAO.Test.main(Test.java:14)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 3 more

And when I added it, All of this disappeared and the error first described (Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory)is appearing now. Can someone tell me what to do?/

Thanks.


Top
 Profile  
 
 Post subject: possible resolution
PostPosted: Sun Nov 30, 2008 5:00 am 
Newbie

Joined: Sun Nov 30, 2008 4:49 am
Posts: 2
Am new to hibernate. I faced the same problem. May be my experience helps..
I had slf4j-api-1.5.2 in my webapp's WEB-INF/lib directory
When I added latest version slf4j-log4j12-1.5.6.jar.
This gave me the same error reported by you.

I removed this jar and added earlier version (same as that of sl4j-api) slf4j-simple-1.5.2.jar

I have added 'simple' instead of 'log4j' but it should not matter
This resolved the issue.

Hope it works for u :)

phoneynk


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 30, 2008 11:33 pm 
Newbie

Joined: Wed Apr 23, 2008 3:36 pm
Posts: 6
Thanks phoneynk, that was nice of you and it worked. But only once :(. It's now giving StackOverflow Exception. It would be nice if someone can actually tell me what all jar files I need to exactly have in my classspath for hibernate with annotations to work. I keep putting all the jar files I find and maybe it's because of that the new exception.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 11:43 pm 
Newbie

Joined: Wed Apr 23, 2008 3:36 pm
Posts: 6
Um... Anybody?/

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 11:47 pm 
Newbie

Joined: Wed Apr 23, 2008 3:36 pm
Posts: 6
Oops sorry got re posted.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2008 6:39 pm 
Newbie

Joined: Tue Dec 02, 2008 6:00 pm
Posts: 1
Location: South Afric
Hi Everyone.

Class org.slf4j.impl.StaticLoggerBinder located in slf4j-api has static class member with public modifier:
Code:
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

The same static class member located in slf4j-log4j12, but it has private modifier:
Code:
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

Because java see last one and it private - code can't find SINGLETON.

Solution.
Change modifier from private to public for StaticLoggerBinder SINGLETON in org.slf4j.impl.StaticLoggerBinder located in slf4j-log4j12 (or just copy that code from slf4j-api) and rebuild it. You code will be like that:
Code:
...
package org.slf4j.impl;

import org.apache.log4j.Level;
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.Util;
import org.slf4j.spi.LoggerFactoryBinder;

/**
* The binding of {@link LoggerFactory} class with an actual instance of
* {@link ILoggerFactory} is performed using information returned by this class.
*
* @author Ceki G&uuml;lc&uuml;
*/
public class StaticLoggerBinder implements LoggerFactoryBinder {

  /**
   * The unique instance of this class.
   *
   */
  public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

...

_________________
Best Regards, Sergey Akopkokhyants


Top
 Profile  
 
 Post subject: Re: Hibernate Annotations Error
PostPosted: Sat Dec 13, 2008 9:10 pm 
Newbie

Joined: Wed Sep 06, 2006 1:02 pm
Posts: 3
Hello

I faced the same problem today.
The solution is much simpler :)

hibernate-distribution-3.3.1.GA distribution comes with:
hibernate-3.3.1.GA\lib\required\slf4j-api-1.5.2.jar

But you trying to use slf4j-log4j12-1.5.6.jar which comes with newer version of slf4j framework.

As we can see those two files (from older and newer version of slf4j) cannot talk to each other causing an exception.

Solution:
1. Remove file:
hibernate-3.3.1.GA\lib\required\slf4j-api-1.5.2.jar

2. Add to your project two new files:
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar

Regards,
Adam Wozniak


Top
 Profile  
 
 Post subject: That's great
PostPosted: Sat Dec 20, 2008 7:42 am 
Newbie

Joined: Sat Dec 20, 2008 7:38 am
Posts: 1
Thank you, Adamzpl

I love your solution.
It works well now.


Top
 Profile  
 
 Post subject: Yep, this helped me too
PostPosted: Mon Dec 22, 2008 4:21 am 
Newbie

Joined: Mon Dec 22, 2008 4:18 am
Posts: 1
Thanks also, Adam. This is exactly the fix I needed at midnight setting up Hibernate for a new course. (Always nice to get help from a former student, too :))

_________________
Dr. Clinton Staley


Top
 Profile  
 
 Post subject: Thanks a lot!
PostPosted: Thu Jan 15, 2009 6:21 pm 
Newbie

Joined: Thu Jan 15, 2009 6:15 pm
Posts: 1
Location: Colima,Colima,Mexico
I've checked the solution given by adamzpl and it works efficiently. Thanks a lot from Mexico.

_________________
"Nunca consideres el estudio como una obligación, sino como una oportunidad para penetrar en el bello y maravilloso mundo del saber."


Top
 Profile  
 
 Post subject: Re: possible resolution
PostPosted: Wed Feb 11, 2009 5:39 am 
Newbie

Joined: Mon Feb 09, 2009 8:46 am
Posts: 4
phoneynk wrote:
Am new to hibernate. I faced the same problem. May be my experience helps..
I had slf4j-api-1.5.2 in my webapp's WEB-INF/lib directory
When I added latest version slf4j-log4j12-1.5.6.jar.
This gave me the same error reported by you.

I removed this jar and added earlier version (same as that of sl4j-api) slf4j-simple-1.5.2.jar

I have added 'simple' instead of 'log4j' but it should not matter
This resolved the issue.

Hope it works for u :)

phoneynk


What about this exception : "java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory"

any solution for it ?

_________________
Thanks
Sherif


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 4:18 am 
Newbie

Joined: Fri Feb 13, 2009 4:07 am
Posts: 1
Hi, I registered just to answer this since i went through the same thing. Here's the solution:

If you want to use log4j, you will need the following files:
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
log4j-1.2.15.jar

Note that the above are the latest version of slf4j (1.5.6) and log4j (1.2.15). The two slf4j must be of the same version!

Once you run with this setup, you will be prompted with these warning:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

This means you must create log4j.properties in your source directory (or depends on your configuration, i think it must be together with hibernate.cfg.xml). There is a readily available log4j.properties in hibernate package in \tutorials\web\src\main\resources

For the complete hibernate with postgreSQL setup tutorial (with screenshots!!!) go to: http://www.nabble.com/org.slf4j.impl.St ... 87705.html

Hope this helps! Ü


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 14, 2009 2:17 am 
Newbie

Joined: Mon Feb 09, 2009 8:46 am
Posts: 4
Thanks the problem was solved ,

Thanks all for the help..

_________________
Thanks
Sherif


Top
 Profile  
 
 Post subject: Re: Hibernate Annotations Error
PostPosted: Mon Jul 18, 2011 6:52 am 
Newbie

Joined: Fri Jul 15, 2011 6:54 am
Posts: 3
Just change slf4j-api-1.4.3.jar to slf4j-simple-1.4.3.jar. That worked for me to get rid of the ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.