9

I have one simple @Singleton whitin Java EE project that parses data from internet and saves it with Hibernate to 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();
    }
}

But I'm getting this

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

Pointing to

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

But hibernate.cfg.xml works well within Java SE project, and within Java EE I'm getting this error. All JARs that I used are in /WEB-INF/lib. hibernate.cfg.xml is in src folder and in /WEB-INF folder. And I'm using GlassFish without any containers and building tools, which I think is bad, but I need to know where mistake was made in this simple example.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
showgazer
  • 91
  • 1
  • 1
  • 5
  • I have same problem. But only with GlassFish. Tomcat works normaly. – Igor Bobko Nov 08 '15 at 23:31
  • Switching from hibernate 5 to 4 fixes this error, so I think that the cause of it are some old GlassFish JPA jars that pointing to no longer existed methods in hibernate core. – showgazer Nov 12 '15 at 08:32

3 Answers3

8

I solved this problem by deleting jboss-logging jar file from project's lib folder and replacing jboss-logging.jar from glassfish\modules folder to last version from http://mvnrepository.com/artifact/org.jboss.logging/jboss-logging/3.3.0.Final

Igor Bobko
  • 342
  • 2
  • 13
  • your CoreMessageLogger do not have debugf method... are you sure you replace jar file everywhere? Check version runtime. – Igor Bobko Nov 11 '15 at 09:42
  • Yup, I deleted jboss from lib and update the one from glassfish. You shure that you do not think about `org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V `? – showgazer Nov 12 '15 at 08:23
  • I sure Glassfish has wrong version of jboss.logging. So this error occurs. Find what jboss.logging glassfish loads and check is there debugf method in it – Igor Bobko Nov 18 '15 at 06:22
  • do not forget to restart glassfish, it worked for me never the less this feels a bit "dirty" I tried specifying the dependency in my pom but it was still using the one provided by glassfish, I would really like to have a "cleaner" solution, i do not think that digging in glassfish guts its the right approach, if someone finds a better solution I will appreciate them letting me know – Ordiel Jan 03 '16 at 17:29
2

It seems like there's a version mismatch between the logging libs included in the application server and the logging libs required by Hibernate.

I had the same problem and my configuration was: Jboss AS 7.1.1.Final and Hibernate 5.1.0 and I solved excluding the jboss logging module in the jboss-deployment-structure.xml

    <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>
kekolab
  • 801
  • 10
  • 24
0

The silver bullet for fixing all these maddening version compatibility issues, is to use the Spring IO Platform

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

which does dependency management for everything in Spring via Maven or Gradle.

(After this you do not have to tear your hair and worry about arcane version issues that the typical developer has to keep track of and suffer through every few months when updating or adding projects).

Also Note: You also need to make sure that all your modules (in a multi-module project) share same version numbers. It sounds obvious but one can forget this when adding modules.

Toothless Seer
  • 798
  • 9
  • 13