web-dev-qa-db-ja.com

Hibernate 5.2.7-Java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / util / Map;

gradleでHibernate 5.2.7を使用している間、Java MariaDB 10.1.19に接続するプロジェクト、Exception in thread "main" Java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;

完全なスタックトレース

 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)

私はいくつかのアプローチ(他のHibernateバージョン5.2.6および5.2.)を試し、インターネットでヘルプを検索しましたが、どの提案も機能しませんでした。

ここで例外が発生します。

    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();
}

また、次のコードを試して同じ結果を得ました:

    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();
    }

私のhibernate.cfg.xmlは次のようになります

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

Gradleに含まれるjarファイルは次のとおりです。

// 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'
}

ヘルプやアドバイスは大歓迎です

12
Marcel

この問題は、クラスパスにJPA APIの古い互換性のないコピーがあるために発生します。

具体的には:

  • javax.persistence:persistence-api:1.0.2

JPA 2.1 APIの適切なバージョンとの競合:

  • org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final

残念ながら、Maven 3は同じアーティファクトの再配布を処理できません。これは時々必要です。

11
Sanne

Gradleのバージョンは何ですか?

Gradleを3.5から4.3にアップグレードした後に発生するのと同じエラーがあるため、お願いします。同じHibernateバージョン(5.2.9)、同じSpring Boot(1.5.8)ですが、Gradleで3.5.-OK、4.3は失敗します。

私はテストしましたが、正常に動作する最新バージョンは私にとっては3.5.1でした。 4.0から4.4-rc-6までのバージョンをテストしました(現時点では最新です)。

distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.Zip
6