NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf (Ljava / lang / String; I) V

This was the day I am trying to use Junit to test hibernate integration. I am very new to integration test, so I want to be doing something wrong. I found this example on githhub: hibernate junit test example I have upload and try and it works, so I am trying to copy dependencies and class on my pom (because my goals are to use my internal db in the future and check my functions that I already wrote) and copy this class:

package org.hibernate.tutorial.annotations;
import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class AnnotationsIllustrationTest extends TestCase {
private SessionFactory sessionFactory;

@Override
protected void setUp() throws Exception {
    // A SessionFactory is set up once for an application
    sessionFactory = new Configuration()
            .configure() // configures settings from hibernate.cfg.xml
            .buildSessionFactory();
}

@Override
protected void tearDown() throws Exception {
    if ( sessionFactory != null ) {
        sessionFactory.close();
    }
}

@SuppressWarnings({ "unchecked" })
public void testBasicUsage() {
    // create a couple of events...
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    session.close();

    // now lets pull events from the database and list them
    session = sessionFactory.openSession();
    session.beginTransaction();
    List result = session.createQuery( "from Event" ).list();
//      for ( Event event : (List<Event>) result ) {
//          System.out.println( "Event (" + event.getDate() + ") : " +     event.getTitle() );
//      }
    session.getTransaction().commit();
    session.close();
}

      

but when I try to execute "Junit test" or "Maven test" I have this error: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf (Ljava / lang / String; I) V

I see that the problem is with a dependency, so I tried to change the version of my dependencies, use some dependencies with test only, but it doesn't change anything ... here's my pom:

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.7</java.version>

    <!-- JBoss dependency versions -->
    <version.jboss.maven.plugin>7.1.1.Final</version.jboss.maven.plugin>

    <bcpkix-jdk15on.version>1.48</bcpkix-jdk15on.version>
    <cxf-bundle.version>2.5.2</cxf-bundle.version>
    <javax.ejb-api.version>3.2</javax.ejb-api.version>

    <commons-codec.version>1.6</commons-codec.version>
    <commons-configuration2.version>2.0</commons-configuration2.version>
    <commons-io.version>2.4</commons-io.version>
    <commons-lang.version>2.6</commons-lang.version>
    <commons-logging.version>1.2</commons-logging.version>
    <commons-logging-api.version>1.1</commons-logging-api.version>
    <commons-net.version>3.4</commons-net.version>
    <commons-collections.version>3.2.2</commons-collections.version>
    <commons-fileupload.version>1.2</commons-fileupload.version>

    <fluent-hc.version>4.3.6</fluent-hc.version>
    <httpclient-osgi.version>4.2.1</httpclient-osgi.version>
    <httpclient-cache.version>4.3.6</httpclient-cache.version>
    <httpcore.version>4.3.3</httpcore.version>
    <httpmime.version>4.3.6</httpmime.version>
    <log4j.version>1.2.17</log4j.version>
    <mysql-connector-java>5.1.31</mysql-connector-java>


    <!-- Maven Plugin -->
    <maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
    <maven-source-plugin.version>3.0.0</maven-source-plugin.version>
    <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
    <maven-war-plugin.version>2.6</maven-war-plugin.version>
    <jdk.source>1.7</jdk.source>
    <jdk.target>1.7</jdk.target>

</properties>


<dependencies>

    <!-- Not provided: -->
    <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>${commons-codec.version}</version>
    </dependency>


    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-configuration2</artifactId>
        <version>${commons-configuration2.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>${commons-lang.version}</version>
    </dependency>

    <!-- Commons Logging -->

    <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging-api -->
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging-api</artifactId>
        <version>${commons-logging-api.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>${commons-logging.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-net/commons-net -->
    <dependency>
        <groupId>commons-net</groupId>
        <artifactId>commons-net</artifactId>
        <version>${commons-net.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.persistence/com.springsource.javax.persistence -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version> <!-- In questo modo prende la versione da sopra -->
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient-cache</artifactId>
        <version>${httpclient-cache.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>${httpcore.version}</version>
    </dependency>


    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>${httpmime.version}</version>
    </dependency>


    <!-- Da qui in poi sono tutti Provided: -->
    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-web</artifactId>
        <version>${version.jboss.maven.plugin}</version>
        <scope>provided</scope>
    </dependency>

    <!-- Per Base32 -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient-osgi</artifactId>
        <version>${httpclient-osgi.version}</version>
        <scope>provided</scope>
    </dependency>

    <!-- Database -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql-connector-java}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>javax.ejb-api</artifactId>
        <version>${javax.ejb-api.version}</version>
        <scope>provided</scope>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpkix-jdk15on</artifactId>
        <version>${bcpkix-jdk15on.version}</version>
        <!-- <scope>provided</scope> -->
    </dependency>


    <!-- CXF -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle</artifactId>
        <version>${cxf-bundle.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>fluent-hc</artifactId>
        <version>${fluent-hc.version}</version>
        <scope>provided</scope>
    </dependency>

    <!-- Prova Junit -->

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
    </dependency>

    <!-- The H2 in-memory database -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.2.145</version>
    </dependency>

   <!--  to use Hibernate as the JPA provider at a guess! -->
   <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.2.Final</version>
    </dependency>


</dependencies>
<!-- build -->
<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <finalName>${project.artifactId}</finalName>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>${version.jboss.maven.plugin}</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>${jdk.source}</source>
                <target>${jdk.target}</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven-war-plugin.version}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <archive>
                    <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>

    </plugins>
</build>

      

Some dependencies are provided because I am using jboss to deploy my project; I also copied persistence.xml and hibernate.cfg.xml to src / test / resources.

What am I doing wrong? Is there a best practice for doing what I want to do?

+3


source to share


1 answer


As I said, I had a similar problem and in my case, I decided to check the maven dependency tree ... I use this command in my prompt:

mvn dependency: tree -Dverbose and after reading the answer I found that the library was declared twice, but it was not a Hibernate library and only caused this issue after my migration from hibernate4 to hibernate5.



I hope this is helpful for anyone else having this problem.

+1


source







All Articles