本文介绍了Hibernate 5.2.7 - java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / util / Map;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Gradle Java Project中使用Hibernate 5.2.7连接到MariaDB 10.1.19时,我在线程mainjava.lang.NoSuchMethodError:org.hibernate.engine中得到了一个异常.spi.SessionFactoryImplementor.getProperties()Ljava / util / Map;



完整的堆栈跟踪

 线程main中的异常java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / util / Map; 
。在org.hibernate.internal.CacheImpl<初始化>(CacheImpl.java:71)
。在org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:28)
。在在org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:58)
org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:20)
。在组织。 hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
处org.hibernate.service org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
。 internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
。在org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.getService(SessionFactoryServiceRegistryImpl.java:77)LT
。在org.hibernate.internal.SessionFactoryImpl&; init>(SessionFactoryImpl.java:240)
at org.hibernate.boot.internal.Sessio nFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
在quantitativeAnalysis.backend.dataCollector.dataCollectorManager.createFactory(dataCollectorManager.java: 280)
。在quantitativeAnalysis.volatilityAnalyzer.volatilityDynamicImpl.openInstance(volatilityDynamicImpl.java:18)
。在frontend.MainFrame.main(MainFrame.java:96)

我尝试了几种方法(其他Hibernate版本 5.2.6 5.2.3 )并搜索互联网寻求帮助,但没有任何建议。



例外发生在这里:

  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()//配置hibernate.cfg.xml中的设置
.build();

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

我的hibernate.cfg.xml看起来像这样



 < session-factory> 

<! - < 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>建立< / property>

< mapping resource =resources / BitcoinDaysDestroyed.hbm.xml/>
< mapping resource =resources / BitcoinPrice.hbm.xml/>
< mapping resource =resources / BitcoinTransactions.hbm.xml/>

< / session-factory>


我用Gradle如下所示:

  //应用java插件添加对Java 
的支持apply plugin:'java'

//在本节中,您声明在哪里查找项目的依赖关系
存储库{
//使用jcenter解决您的依赖关系。
//你可以在这里声明任何Maven / Ivy /文件库。
// jcenter()
mavenCentral()

maven {
urlhttps://maven.elasticsearch.org/releases
}
}

依赖关系{
//产品代码使用Guava
编译'com.google.guava:guava:20.0'

/ / QuantitativeAnalysis

// https://mvnrepository.com/artifact/com.toedter/jcalendar
编译组:'com.toedter',名称:'jcalendar',版本:'1.4 '

// https://mvnrepository.com/artifact/javax.persistence/persistence-api
编译组:'javax.persistence',名称:'persistence-api',版本:'1.0.2'

// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
编译组:'com.googlecode.json '简单',名称:'json-simple',版本:'1.1.1'

// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
编译组:'org.apache.httpcomponents',名称:'httpclient',版本:'4.5.2'

// https:// mvnrep ository.com/artifact/org.apache.httpcomponents/httpcore
编译组:'org.apache.httpcomponents',名称:'httpcore',版本:'4.4.5'

/ / https://mvnrepository.com/artifact/org.hibernate/hibernate-core
//编译组:'org.hibernate',名称:'hibernate-core',版本:'5.2.6.Final'

//antlr-2.7.7.jar,从src编译
编译文件('libs / antlr-2.7.7.jar')

// classmate-1.3.0.jar,由src编译
编译文件('libs / classmate-1.3.0.jar')

//dom4j-1.6.1.jar,编译自src
编译文件('libs / dom4j-1.6.1.jar')

//antlr-2.7.7.jar,从src编译
编译文件('libs /geronimo-jta_1.1_spec-1.1.1.jar')

//jandex-2.0.3.Final.jar,由src编译
编译文件('libs / jandex-2.0 .3.Final.jar')

//javassist-3.20.0-GA.jar,从src编译
编译文件('libs / javassist-3.20.0-GA.jar ')

//jboss-logging-3.3.0.Final.jar,comp从src
编译文件('libs / jboss-logging-3.3.0.Final.jar')

//hibernate-commons-annotations-5.0.1.Final.jar,编译自src
编译文件('libs / hibernate-commons-annotations-5.0.1.Final.jar')

//hibernate-jpa-2.1-api-1.0.0。 Final.jar,从src编译
编译文件('libs / hibernate-jpa-2.1-api-1.0.0.Final.jar')

//hibernate-core-5.2。 7.Final.jar,编译自src
编译文件('libs / hibernate-core-5.2.7.Final.jar')

//c3p0-0.9.5.2,编译自src
编译文件('libs / c3p0-0.9.5.2.jar')

//hibernate-c3p0-5.2.7.Final.jar,从src编译
编译文件('libs / hibernate-c3p0-5.2.7.Final.jar')

//mchange-commons-java-0.2.11.jar,从src编译
编译文件( 'libs / mchange-commons-java-0.2.11.jar')

// https://mvnrepository.com/artifact/mysql/mysql-connector-java
编译组: 'mysql',名称:'mysql-connector-java',版本:'6.0.5

// QualitatitveAnalysis

// https://mvnrepository.com/artifact/log4j/log4j
编译组:'log4j',名称:'log4j' ,版本:'1.2.17'

// https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch
编译组:'org.elasticsearch',名称:'elasticsearch ',版本:'2.1.0'

// https://mvnrepository.com/artifact/org.elasticsearch.plugin/shield
编译组:'org.elasticsearch.plugin' ,名称:'shield',版本:'2.1.0'

// https://mvnrepository.com/artifact/com.google.code.gson/gson
编译组: 'com.google.code.gson',名称:'gson',版本:'2.8.0'

// https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core
编译组:'org.twitter4j',名称:'twitter4j-core',版本:'4.0.6'

// https://mvnrepository.com/artifact/javax。 json / javax.json-api
编译组:'javax.json',名称:'javax.json-api',版本: '1.0'

// jReddit Jar,由src编译
编译文件('libs / jReddit-1.0.4-SNAPSHOT.jar')

//使用JUnit测试框架
testCompile'junit:junit:4.12'
}

任何帮助或建议,高度赞赏

解决方案

这个问题是由于在类路径中有一个旧的,不兼容的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仍然无法处理重新分配相同的工件,有时这是必要的。


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

The complete stacktrace

 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:

    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:

    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

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

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

解决方案

This problem is caused by having an old, incompatible copy of the JPA API on the classpath.

Specifically:

  • javax.persistence:persistence-api:1.0.2

Conflicts with the right version of the JPA 2.1 API:

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

Unfortunately Maven 3 is still unable to handle re-distributions of the same artifacts, which are sometimes necessary.

这篇关于Hibernate 5.2.7 - java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / util / Map;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 06:01
查看更多