0

i try to Hibernate generation code but i got this error :

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:550)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:860)
at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:120)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:93)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:43)
at org.jboss.tools.hibernate3_5.console.ConsoleExtension3_5$2.execute(ConsoleExtension3_5.java:255)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.jboss.tools.hibernate3_5.console.ConsoleExtension3_5.buildConfiguration(ConsoleExtension3_5.java:223)

My pom.xml before i have many dependency (hibernate-core) but i choose to remove them to see if it's work but i still got the error.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-     4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
  <groupId>pagesjaunes</groupId>
  <artifactId>pagesjaunes</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <warSourceDirectory>WebContent</warSourceDirectory>
      <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
  </plugin>
</plugins>

Hayi
  • 6,972
  • 26
  • 80
  • 139

1 Answers1

0

Typical java.lang.NoSuchMethodError

Check Javadocs, it says

a. Thrown if an application tries to call a specified method of a class (either
   static or instance), and that class no longer has a definition of that method.

b. Normally, this error is caught by the compiler; this error can only occur at 
   runtime if the definition of a class has incompatibly changed.

Why does it takes place ?

The very best possible explanantion for such error is-

Whenever we try to access a method from the .jar file which will be explored at the time of Run time itself; at compile time such kind of error wont get captured.

For instance take an example of

User.java

Class User {
    public String firstName;
    public String lastName;

    public void String getName() {
        return firstName +" " +lastName;
    }
}

Suppose we export it as a jar and exported it in another project for and we use it for our purpose.

Note - Include your jar file here.

import com.vinayak.User;

class PatternMatch {
    public static void main (String args[]) {
        User u = new User();
        System.out.println(u.accessName());//This will throw a 
                                          //No such method error
    }
}

Whole point of explaining it is, if you try to access a method which is not present in that jar at that time you will face such kind of situtation.

So please check are you using correct version of it or not. Its present in SLF4J 1.7.5

Refer Find where java class is loaded from for more understanding.

Community
  • 1
  • 1
Vinayak Pingale
  • 1,315
  • 8
  • 19
  • thanks but i didn't put any dependency in my pom.xml, i thinks the jar come with hibernate tools of eclipse and i don't where he put them to change version. – Hayi Jan 16 '14 at 09:27
  • can you share pom.xml? – Vinayak Pingale Jan 16 '14 at 09:30
  • i google it and i found some response they say it's `It was the classpath of my project conflicting with the plugin's classpath.` – Hayi Jan 16 '14 at 09:41
  • yes it is not a bug , as you have used hibernate tool it has added slf4j for you. either remove these jars, jcl-over-slf4j-1.6.1.jar jul-to-slf4j-1.6.1.jar slf4j-api-1.6.1.jar slf4j-ext-1.6.1.jar logback-classic-0.9.26.jar logback-core-0.9.26.jar OR use exclusions tag in pom.xml to exclude common-logging – Vinayak Pingale Jan 16 '14 at 09:47
  • how can i remove jars from plugin ? i can't found them ! – Hayi Jan 16 '14 at 09:50
  • Because i didn't put any dependency in pom.xml to exclude them ! – Hayi Jan 16 '14 at 09:51
  • and what i don't understand it's that before some days all it's work for me !! – Hayi Jan 16 '14 at 09:52
  • Go to eclipse installation location--->plugin folder search for hibernate tools. and try to remove SLF4J. at my side it looks like this. \plugins\org.jboss.tools.hibernate4_0_3.7.1.Final-v20131205-0918-B107\lib – Vinayak Pingale Jan 16 '14 at 09:53
  • Yes hibernate tools get a SLF4j jar "slf4j-log4j12-1.5.8" – Vinayak Pingale Jan 16 '14 at 09:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45353/discussion-between-vinayak-pingale-and-youssef) – Vinayak Pingale Jan 16 '14 at 09:54