-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Mon Jan 23, 2017 6:11 am 
Newbie

Joined: Sun Jan 22, 2017 7:36 pm
Posts: 3
Hey,

I have used Hibernate in older days and after a break of 5 years doing other stuff, I have returned to it, but I face a problem, where I kindly ask for your help

While using Hibernate 5.2.7 in a Gradle Eclipse Java (SE8 1.8) Project to connect to a MariaDB 10.1.19, I am getting an
Quote:
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;


when I hit the "Run as application" button via the Eclipse interface after the Gradle build returned successful.

The complete stacktrace
Code:
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:71)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:28)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:20)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:58)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.getService(SessionFactoryServiceRegistryImpl.java:77)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:240)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at quantitativeAnalysis.backend.dataCollector.dataCollectorManager.createFactory(dataCollectorManager.java:280)
at quantitativeAnalysis.volatilityAnalyzer.volatilityDynamicImpl.openInstance(volatilityDynamicImpl.java:18)
at frontend.MainFrame.main(MainFrame.java:96)


I have tried several approaches (other Hibernate Versions 5.2.6 and 5.2.3) and searched the internet for help, but none of the suggestions worked.

The Exception occur here:
Code:
    Configuration configuration = new Configuration().configure();

    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
    try{
        factory = configuration.buildSessionFactory(ssrb.build());
    }catch(Exception ex){
    System.err.println("Failed to configure Sessionfactory");
    ex.printStackTrace();
}

I have also tried the following code leading to the same result:
Code:
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
    .configure() // configures settings from hibernate.cfg.xml
    .build();

try {
    factory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
    }catch(Exception ex){
    System.err.println("Failed to configure Sessionfactory");
    ex.printStackTrace();
    }

My hibernate.cfg.xml looks like this
Code:
<session-factory>

    <!-- Database connection settings -->
    <!-- <property name="connection.driver_class">com.mysql.jdbc.Driver</property> -->
    <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>       
    <property name="connection.url">jdbc:mysql://localhost:3307/VolatilityData</property>
    <property name="connection.username">XXX</property>
    <property name="connection.password">XXX</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>


    <!--  -->
    <property name="hbm2dll.auto">create</property>

    <!-- mapping content -->
    <mapping resource="resources/BitcoinDaysDestroyed.hbm.xml"/>
    <mapping resource="resources/BitcoinPrice.hbm.xml"/>
    <mapping resource="resources/BitcoinTransactions.hbm.xml"/>

</session-factory>

The jars I include with Gradle are the following:
Code:
// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your   project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
//jcenter()
mavenCentral()

maven {
url "https://maven.elasticsearch.org/releases"
  }
}

dependencies {
// The production code uses Guava
compile 'com.google.guava:guava:20.0'

//QuantitativeAnalysis

// https://mvnrepository.com/artifact/com.toedter/jcalendar
compile group: 'com.toedter', name: 'jcalendar', version: '1.4'

// https://mvnrepository.com/artifact/javax.persistence/persistence-api
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0.2'

// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.5'

// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
//compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.6.Final'

//antlr-2.7.7.jar, compiled from src
compile files('libs/antlr-2.7.7.jar')

//classmate-1.3.0.jar, compiled from src
compile files('libs/classmate-1.3.0.jar')

//dom4j-1.6.1.jar, compiled from src
compile files('libs/dom4j-1.6.1.jar')

//antlr-2.7.7.jar, compiled from src
compile files('libs/geronimo-jta_1.1_spec-1.1.1.jar')

//jandex-2.0.3.Final.jar, compiled from src
compile files('libs/jandex-2.0.3.Final.jar')

//javassist-3.20.0-GA.jar, compiled from src
compile files('libs/javassist-3.20.0-GA.jar')

//jboss-logging-3.3.0.Final.jar, compiled from src
compile files('libs/jboss-logging-3.3.0.Final.jar')

//hibernate-commons-annotations-5.0.1.Final.jar, compiled from src
compile files('libs/hibernate-commons-annotations-5.0.1.Final.jar')

//hibernate-jpa-2.1-api-1.0.0.Final.jar, compiled from src
compile files('libs/hibernate-jpa-2.1-api-1.0.0.Final.jar')

//hibernate-core-5.2.7.Final.jar, compiled from src
compile files('libs/hibernate-core-5.2.7.Final.jar')

//c3p0-0.9.5.2, compiled from src
compile files('libs/c3p0-0.9.5.2.jar')

//hibernate-c3p0-5.2.7.Final.jar, compiled from src
compile files('libs/hibernate-c3p0-5.2.7.Final.jar')

//mchange-commons-java-0.2.11.jar, compiled from src
compile files('libs/mchange-commons-java-0.2.11.jar')

// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'

//QualitatitveAnalysis

// https://mvnrepository.com/artifact/log4j/log4j
compile group: 'log4j', name: 'log4j', version: '1.2.17'

// https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch
compile group: 'org.elasticsearch', name: 'elasticsearch', version: '2.1.0'

// https://mvnrepository.com/artifact/org.elasticsearch.plugin/shield
compile group: 'org.elasticsearch.plugin', name: 'shield', version: '2.1.0'

// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'

// https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.6'

// https://mvnrepository.com/artifact/javax.json/javax.json-api
compile group: 'javax.json', name: 'javax.json-api', version: '1.0'

//jReddit Jar, compiled from src
compile files('libs/jReddit-1.0.4-SNAPSHOT.jar')

// Use JUnit test framework
testCompile 'junit:junit:4.12'
}

Any help or advice is highly appreciated


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Mon Jan 23, 2017 7:59 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Marcel,
I double checked the code, and these releases do have the method which seems missing in your exception.

Your gradle file seems to mention the right dependency versions. It would seem you're not actually running those versions though?

The gradle file also mentions "compiled from src" on several key dependencies. Possibly something went wrong there?
I'd suggest to try the official builds and double check that your build is actually using the versions you listed.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Mon Jan 23, 2017 8:05 am 
Newbie

Joined: Sun Jan 22, 2017 7:36 pm
Posts: 3
Thanks Sanne for your quick reply, I have used Hibernate 5.2.6 before which I included into gradle

Code:
// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
//compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.6.Final'

from mavenCentral()


It produces the same exception.

I have commented this section to switch to Hibernate 5.2.7 and used the jars which I have downloaded from the Hibernate website.
"compiled from src" is a bit misleading, it is for me the hint, that I am using the jars stored in the lib folder instead those downloaded from MavenCentral


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Mon Jan 23, 2017 8:12 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I saw the problem now:

Remove:
Code:
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0.2'


And replace it with the right version, which is:
Code:
compile files('libs/hibernate-jpa-2.1-api-1.0.0.Final.jar')


the javax.persistence:persistence-api is containing the same API definition, but version 1.0.2 is old and outdated.

I think that might solve your problem, as the missing method is declared in one of the JPA interfaces.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Tue Jan 24, 2017 5:21 am 
Newbie

Joined: Sun Jan 22, 2017 7:36 pm
Posts: 3
Many thanks, it solved the problem.

Just in the interest of learning: How could I have seen it by myself (especially as non-experienced user) or is it only possible by having a near-complete overview about the different jars like you have?

Many thanks again for your help!


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Tue Jan 24, 2017 7:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can use the dependency graph report:

Code:
> gradle htmlDependencyReport


and then you'll see that you have multiple versions of the same dependency.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.7 - java.lang.NoSuchMethodError: org.hibernate
PostPosted: Tue Jan 24, 2017 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
It's a good question. In this case the dependency report would have been useful, but you'd need to actually know that those artifacts contain the same classes.. not necessarily trivial since they have different ids.

I started investigating from the specific error message; it means that the method should be there but it wasn't in your case. I noticed by opening the sources that the method is defined on the JPA API; so one possible explanation was that you had either a wrong build (as I asked before), or maybe that you had the wrong JPA API on the classpath.. then I noticed it.

I wish Maven & Gradle had a better way to identify "same artifact" other than the groupid/artifactId combination, as it's a common problem that they allow these duplicates. Sadly organizations and licenses forced many companies to re-release their own edition of many Java EE APIs, so watch our for these artifacts to not be duplicated.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.