Getting an hibernate3 SessionFactory

I keep getting this message

java.lang.NoSuchMethodError: 'org.hibernate.classic.Session org.hibernate.SessionFactory.getCurrentSession()'

From what I have read this happens if i have Hibernate 3 jars on the classpath. I can’t figure out where it would come from. I have searched all jars named hibernate looked into them and I can’t find the classic Session class anywhere. Can this be the problem in my case?

I am starting to believe that I have configuration that creates this session factory (maybe classpath entry). What selects the instance of sessionfactory when it is created from configuration?

Any tips on what I can do?

You should see what the calling method is in the stack trace.

I don’t really get good stacktrace.

It fails on this line:
SessionFactoryHelper.getInstance().getCurrentSession();

Where getInstance() somehow gets an hibernate3 session factory.

I create the session factory with this code:

Configuration cfg = getConfiguration();
sessionFactory = cfg.buildSessionFactory();

This is the code in getConfiguration()

           Map<String, String> propMap = SystemConfiguration.getPropertyMap("hibernate.", false);

            Properties props = new Properties();
            props.putAll(propMap);

            if (LOG.isLoggable(Level.FINER))
            {
                String msg = "hibernate properties: " + props;
                LOG.logp(Level.FINER, CLASS_NAME, methodName, msg);
            }

            /* Init a hibernate configuration with the props Property */
            cfg = new Configuration();
            cfg.setProperties(props).addResource("idainfront/digg/adapter/interceptors/LogData.hbm.xml");
  

And finally this is the values returned by SystemConfiguration.getPropertyMap()

hibernate.mapping.security.Authenticator=iipax/generic/security/authenticator/Authenticator.hbm.xml
hibernate.mapping.wsfacade.filter=iipax/generic/wsfacade/savedfilters/Filter.hbm.xml
# Product part hibernate
hibernate.default_batch_fetch_size=500
hibernate.transaction.jta.platform=JBossAS
hibernate.transaction.factory_class=org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl
hibernate.transaction.coordinator_class=jta
hibernate.connection.datasource=java:/iipax.db
hibernate.show_sql=false
hibernate.query.factory_class=org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.mapping.processkernel.1=iipax/service/processkernel/event/TimerEventData.hbm.xml
hibernate.mapping.processkernel.2=iipax/service/processkernel/flowchart/ChartNodeData.hbm.xml
hibernate.mapping.processkernel.3=iipax/service/processkernel/flowchart/FlowChartData.hbm.xml
hibernate.mapping.processkernel.4=iipax/service/processkernel/flowchart/NodeTransitionData.hbm.xml
hibernate.mapping.processkernel.5=iipax/service/processkernel/process/CoreProcessData.hbm.xml
hibernate.mapping.processkernel.6=iipax/service/processkernel/process/CoreProcessAttribute.hbm.xml
hibernate.mapping.processkernel.7=iipax/service/processkernel/process/CourierData.hbm.xml
hibernate.mapping.processkernel.8=iipax/service/processkernel/tracer/TraceData.hbm.xml
hibernate.mapping.processkernel.9=iipax/service/processkernel/flowchart/PluginParam.hbm.xml
hibernate.mapping.tfds.menifest=iipax/service/tfds/core/Manifest.hbm.xml
hibernate.mapping.systemlog.logentry=iipax/generic/systemlog/api/LogEntry.hbm.xml
hibernate.mapping.systemlog.notifyconfig=iipax/generic/systemlog/NotifyConfig.hbm.xml
hibernate.mapping.brokerkernel.alarm=iipax/service/brokerkernel/alarm/AlarmConfig.hbm.xml
hibernate.mapping.brokerkernel.mtsq=iipax/service/brokerkernel/api/MtsQuery.hbm.xml
hibernate.mapping.brokerkernel.mtsqc=iipax/service/brokerkernel/api/MtsQueryCondition.hbm.xml
hibernate.mapping.journalIdTemplate=iipax/service/journal/id/access/JournalIdTemplate.hbm.xml
hibernate.interceptor=iipax.service.casekernel.logic.JoinColumnExtractor
hibernate.mapping.CheckItem=iipax/service/checklist/access/CheckItem.hbm.xml
hibernate.mapping.CheckItemHistory=iipax/service/checklist/access/CheckItemHistory.hbm.xml
hibernate.mapping.CheckItemTemplate=iipax/service/checklist/access/CheckItemTemplate.hbm.xml
hibernate.mapping.CheckItemTemplateGroup=iipax/service/checklist/access/CheckItemTemplateGroup.hbm.xml

If your code swallows the exception and just prints the exception message, maybe you should try removing this logging or set a break point on that line to acquire the stack trace.

You got my hopes up. A swallowed exception that could have explained things. But no. There is no swallowed exceptions.

I have now run the code in the debugger. There the assignment work when I run a similar snippet there. I don’t even try to call the same method. There I have org.hibernat.Session getCurrentSession().

I you have given me an idea what is the problem while looking for this swallowed execption. It fails when I start a transansaction with an txutil class that my company has done. It could be something there that is calling the wrong methods.

I have found the problem. It had nothing to do with hibernate it self. I had a build problem issue.

I had a bad SNAPSHOT version in my local cache. Where I had compiled a jar against an old hibernate version.

This kind of problem can be seen with javap -cp <jar> -c className

private org.hibernate.Session getSession();
    Code:
       0: aload_0
       1: getfield      #5                  // Field mSession:Lorg/hibernate/Session;
       4: astore_1
       5: aload_1
       6: ifnonnull     18
       9: invokestatic  #6                  // Method idainfront/digg/adapter/interceptors/SessionFactoryHelper.getInstance:()Lorg/hibernate/SessionFactory;
      12: invokeinterface #7,  1            // InterfaceMethod org/hibernate/SessionFactory.getCurrentSession:()Lorg/hibernate/classic/Session;
      17: astore_1
      18: aload_1
      19: areturn