Hibernate 5 java.lang.NoSuchMethodError org.jboss.

2020-01-28 05:04发布

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] ------------------------------------------------------------------------

15条回答
我命由我不由天
2楼-- · 2020-01-28 05:36

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

查看更多
淡お忘
3楼-- · 2020-01-28 05:37

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>
查看更多
一纸荒年 Trace。
4楼-- · 2020-01-28 05:40

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>
查看更多
不美不萌又怎样
5楼-- · 2020-01-28 05:41

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.

查看更多
成全新的幸福
6楼-- · 2020-01-28 05:44

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.

查看更多
We Are One
7楼-- · 2020-01-28 05:49

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

查看更多
登录 后发表回答