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

时间:2015-11-08 14:49:23

标签: hibernate java-ee glassfish

我有一个简单的@Singleton whitin Java EE项目,它解析来自互联网的数据并将其与Hibernate一起保存到PostgreSQL。

@Startup
@Singleton
public class PSNDBB {

    @PostConstruct
    public void Parser(){

    //getting data

    SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
    Session session=sessionFactory.openSession();
    session.beginTransaction();

    for(Object obj : array){


        GameData game=new GameData();
        session.save(game);


    }

    session.getTransaction().commit();      
    session.close();

    }
}

但我得到了这个

Caused by: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:87)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    at org.showgazer.psn.PSNDBB.Parser(PSNDBB.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.ejb.containers.interceptors.BeanCallbackInterceptor.intercept(InterceptorManager.java:1035)
    at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
    at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:205)
    ... 70 more

指向

SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();

但是hibernate.cfg.xml在Java SE项目中运行良好,而在Java EE中我遇到了这个错误。我使用的所有JAR都在/WEB-INF/lib中。 hibernate.cfg.xml位于src文件夹和/WEB-INF文件夹中。而且我在没有任何容器和构建工具的情况下使用GlassFish,我认为这很糟糕,但我需要知道在这个简单的例子中哪里犯了错误。

3 个答案:

答案 0 :(得分:8)

我通过从项目的lib文件夹中删除jboss-logging jar文件并将glassfish \ modules文件夹中的jboss-logging.jar替换为http://mvnrepository.com/artifact/org.jboss.logging/jboss-logging/3.3.0.Final的最新版本来解决此问题

答案 1 :(得分:2)

似乎应用程序服务器中包含的日志库与Hibernate所需的日志库之间的版本不匹配。

我遇到了同样的问题,我的配置是:Jboss AS 7.1.1.Final和Hibernate 5.1.0,我解决了jboss-deployment-structure.xml中的jboss日志记录模块

    <jboss-deployment-structure>
        <deployment>
            <!-- ADDED -->
            <exclusions>
                <module name="org.hibernate" /> <!-- Escludo l'Hibernate integrato in jboss e uso quello interno -->
                <module name="org.jboss.logging" /> <!-- Escludo li logger integrato in jboss -->
            </exclusions>
            <!-- FINE ADDED -->
            <dependencies>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>

答案 2 :(得分:1)

用于修复所有这些令人抓狂的版本兼容性问题的银弹,是使用Spring IO平台

http://platform.spring.io/platform/

通过Maven或Gradle对Spring中的所有内容进行依赖管理。

(在此之后,您不必扯掉头发并担心典型的开发人员在更新或添加项目时每隔几个月需要跟踪并受到影响的神秘版本问题。) < / p>

另请注意:您还需要确保所有模块(在多模块项目中)共享相同的版本号。这听起来很明显但是在添加模块时可能会忘记这一点。