Hibernate 5 java.lang.NoSuchMethodError org.jboss.logging.Logger.debugf
Asked Answered
A

16

42

I have a problem when I deploy a webapp with hibernate 5

Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:149) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:759) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:490) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372) [spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454) [spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439) [spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) [spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) [spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
... 23 more

With Hibernate 4 everything is OK.

I had a look at the class NamedQueryRepository at line 149. That class is calling the method debugf in this way

        log.debugf( "Checking %s named HQL queries", namedQueryDefinitionMap.size() );

I can not see the problem

Here is my dependency tree

[INFO] ------------------------------------------------------------------------
[INFO] Building app Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ app---
[INFO] +- org.springframework:spring-aspects:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.8.6:compile
[INFO] +- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.1.7.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-orm:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.1.7.RELEASE:test
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.0.0.CR2:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.0.CR2:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  \- org.jboss:jandex:jar:1.2.2.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:5.0.0.CR2:compile
[INFO] |  \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] |     \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
[INFO] +- org.primefaces:primefaces:jar:5.2.RC3:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.2:compile
[INFO] \- net.sourceforge.jtds:jtds:jar:1.2.8:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Archangel answered 21/7, 2015 at 18:35 Comment(0)
E
32

In glass fish This problem is caused by collision with dependencies of glassfish modules. If you check lib list in glassfishdir/modules you would see boss-logging.jar. You can delete it and replace with latest such as org.jboss.logging:jboss-logging:jar:3.3.0.Final. It worked for me.

Eba answered 6/12, 2015 at 22:35 Comment(1)
I had to do this and restart the domain in Payara Server, worked perfectly.Cloudberry
I
17

In my case the culprit was the Jersey bean validator artifact. One of its dependencies, bean-validation-2.4.0-b06.jar contains Jboss logging classes, for some reason. I had to exclude the jersey-bean-validation and bean-validator artifacts from the spring-boot-starter-jersey dependency:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>jersey-bean-validation</artifactId>
                <groupId>org.glassfish.jersey.ext</groupId>
            </exclusion>
            <exclusion>
                <artifactId>bean-validator</artifactId>
                <groupId>org.glassfish.hk2.external</groupId>
            </exclusion>
        </exclusions>
    </dependency>

EDIT: As of spring-boot 1.3.0, this is fixed and the exclusions above are not necessary anymore.

Ir answered 28/8, 2015 at 20:4 Comment(8)
This worked perfectly for me, I needed to add it to the org.glassfish.ext -> jersey-spring3 dependency.Cordle
@danieln I would like to know how you were able to know the offending jar file. mvn dependency plugin only displays 1 level deep and the jboss class is 2 levels deep.Elisabeth
@FrancisZabala you can use your IDE to troubleshoot this, and similar issues. I'm working with Eclipse, and using the Open Type dialog (ctrl-shift-T) and pasting org.jboss.logging.Logger (the class from the exception) in the search field, the offending bean-validator-2.4.0-b31.jar is shown in the results under .m2\repository\org\glassfish\hk2\external\bean-validator\2.4.0-b31, among other results, which are the original jboss-logging jar.Ir
Then I used the POM Dependency Hierarchy tab in Eclipse to search for this artifact, and it does show you that it's under jersey-spring3.Ir
@danieln Thanks! Open Type dialog worked. This tip is really really helpful. Never thought that I can use Open Type dialog. Special thanks for the shortcut key.Elisabeth
Also notice the order of the listing in the Open Type dialog. In case where there is issue, the first listed one is coming from "org.glassfish.ext". Usually if there is something like "L/V", it might be conflict that there are more than one jars. (Ljava/lang/String;I)VBigamist
I am not using spring-boot. But using spring-core 4.2.4, hibernate 5.0.7 and jersey-spring3 2.22.1. But still ran into this error. Fixed it by excluding org.glassfish.hk2.external:bean-validator from org.glassfish.jersey.ext:jersey-spring3:2.22.1 and then adding org.glassfish.jersey.ext:jersey-bean-validation:2.22.1 as a direct dependency.Inherit
@Inherit Awesome catch! Exactly what I was looking for!Vouvray
B
15

Try upgrading jboss-logging.jar to a more recent version. The one you are using does not seem to be compatible with Hibernate 5.

Bowne answered 21/7, 2015 at 18:51 Comment(3)
This is a better solution. I upgrades the jboss-logging.jar to 3.3.0 (search for it inside widlfly installation folders), changed the filename on the module.xml and now everythings works. I'm using Wildfly 8 with hibernate 5.Sawhorse
3.3.0.Final is already in use which is the most up-to-date version as of today (one year later), so there's nothing to upgrade.Harner
The mvn-tree above indicates that the OP is already using org.jboss.logging:jboss-logging:jar:3.3.0.Final. The problem is that another artifact brings the same classes, and is found earlier in the classpath.Alcantar
P
4

I also faced with such kind of problem when deployed ear on weblogic server. Apparently, weblogic also use jboss logging system, and use old version of it.
My fix:
Add "weblogic-application.xml" to META-INF folder with this content:

    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-application>
        <prefer-application-packages>
            <package-name>org.jboss.logging.*</package-name>
        </prefer-application-packages>

        <prefer-application-resources>
            <resource-name>org/jboss/logging/Logger.class</resource-name>
        </prefer-application-resources>
    </weblogic-application>
Palish answered 9/7, 2016 at 18:14 Comment(0)
R
3

I was getting the same error using jersey-spring-3 and hibernate 5.0.1.Final.Excluding org.glassfish.hk2.external:bean-validator from jersy-spring-3 and adding org.glassfish.jersey.ext:jersey-bean-validation worked for me.Here is my final dependency.

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.22.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.glassfish.hk2.external</groupId>
            <artifactId>bean-validator</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-bean-validation</artifactId>
    <version>2.22.2</version>
</dependency>

from :

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.22.2</version>
</dependency>
Rectifier answered 21/4, 2016 at 13:29 Comment(0)
M
2

In all probability you've got an outdated JBoss Logging JAR on the application's classpath. The ...f methods are a relatively new addition to the Logger API. Hibernate 5 directly depends on Logging version 3.3.0, but it is possible that somehwere in your pom.xml you have an overriding dependency to an earlier version. Another possibility is that you are deploying to a JBoss container where the logging API is container-provided. Then you may need to upgrade the JBoss server, or introduce a workaround to prefer classes contributed by your application.

Mechanic answered 21/7, 2015 at 18:53 Comment(2)
In fact, I'm using maven and the jboss-logging is a direct dependency of hibernate 5.Archangel
Exactly. My answer explains how a wrong JAR could be involved despite that. Since your dep tree shows the proper version of JBoss logging, the other option is a class inherited from the container which overrides your application's class. This is BTW a very common problem for logging classes.Mechanic
D
2

Check my answer at NoSuchMethodError: org.jboss.logging.Logger.debugf

Even I was having issues after upgrading to Hibernate 5.2 , and the culprit was "jboss-logging 3.3.0.Final" which I see present in your dependencies too. Following the steps on the link shared in the answer, you can reduce the dependency jboss-logging to 3.2 level which has the required function.

Ducky answered 22/8, 2016 at 14:37 Comment(0)
Z
1

I too faced this issue. This is what fixed it for me

       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
Zucchetto answered 2/2, 2016 at 9:33 Comment(0)
M
1

In my case the issue was caused by an older version of jboss-logging coming as transitive dependency from hibernate-ehcache, which I found by looking into the maven dependencies tree. I solved it by adding the exclusion:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>${hibernate.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.logging</groupId>
                <artifactId>jboss-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Milly answered 19/11, 2016 at 1:38 Comment(0)
D
1

I had the same error, it is solved by First add the dependency of jboss logging jar as follows

<!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
<dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>jboss-logging</artifactId>
    <version>3.3.0.Final</version>
</dependency>

And if the error still exists then add following exlcusion to the maven dependency.

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.12</version>
     <exclusions>
            <exclusion>
                    <groupId>org.glassfish.hk2</groupId>
                    <artifactId>hk2</artifactId>
            </exclusion>
        </exclusions>
</dependency>

After doing these two things, it is working fine for me.I hope it will work for you also.

Dorri answered 29/11, 2018 at 8:42 Comment(0)
N
1

Error that i got was "

Application run failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V

:::
:::
Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V"

i deleted the jboss-logging folder <.m2\repository\org\jboss\logging\jboss-logging> and restarted the jboss server.

The jars got addedback and the error was gone. (i got some other error after that, but atleast this error was gone)

News answered 17/1, 2019 at 11:39 Comment(0)
I
0

I have the same problen with spring4.2.1+hibernate5.0.2+jersey2.23.1. My solution is the same: Excluding org.glassfish.hk2.external:bean-validator from jersy-spring-3 and adding org.glassfish.jersey.ext:jersey-bean-validation.

<dependency>
  <groupId>org.glassfish.jersey.ext</groupId>
  <artifactId>jersey-spring3</artifactId>
  <version>2.23.1</version>
  <exclusions>
    <exclusion>
      <groupId>org.glassfish.hk2.external</groupId>
      <artifactId>bean-validator</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.ext</groupId>
  <artifactId>jersey-bean-validation</artifactId>
  <version>2.23.1</version>
</dependency>

In my product environment, just delete bean-validator-2.4.0-b34.jar and add jersey-bean-validation-2.23.1.jar

Insubordinate answered 28/7, 2016 at 8:43 Comment(0)
H
0

This can be caused if a dependency includes

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.6.2</version>
</dependency>

Exclude it using an exclusions element in dependency.

Harner answered 18/8, 2016 at 21:49 Comment(0)
M
0

JBoss 6.1+??

I set org.jboss.logging for jboss-logging-3.3.0.Final-redhat-1.jar in modules of jboss.

Its works for me.

Att.,

Mettle answered 28/9, 2017 at 23:25 Comment(0)
G
0

You can use Eclipse to find out which jar is causing the problem:

  • Setup a project with all your jars on the classpath
  • Navigate -> Open Type...
  • Type in org.jboss.logging.Logger

This will give you a list of jars which include the class. One of these is out of date and needs to be excluded (refer to other answers for variations on this).

Goddess answered 2/5, 2019 at 4:49 Comment(0)
H
0

My error was caused by GlassFish and I fixed it by configuring glassfish-web.xml:

The Java Servlet specification recommends that a web module's class loader look in the local class loader before delegating to its parent. You can make this class loader follow the delegation inversion model in the Servlet specification by setting delegate="false" in the class-loader element of the glassfish-web.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">

<glassfish-web-app error-url="">
  <context-root>/myContext</context-root>
  <!–– Change this line "true" to "false" -->
  <class-loader delegate="false"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>
Heuristic answered 5/11, 2022 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.