Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 5.2.7-java.lang.NoSuchMethodError:org.Hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;_Java_Hibernate_Nosuchmethoderror - Fatal编程技术网

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

Hibernate 5.2.7-java.lang.NoSuchMethodError:org.Hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;,java,hibernate,nosuchmethoderror,Java,Hibernate,Nosuchmethoderror,在Gradle Java项目中使用Hibernate 5.2.7连接到MariaDB 10.1.19时,我在线程“main”Java.lang.NoSuchMethodError中遇到了一个异常:org.Hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map 完整的堆栈跟踪 Exception in thread "main" java.lang.NoSuchMethodError: org.hi

在Gradle Java项目中使用Hibernate 5.2.7连接到MariaDB 10.1.19时,我在线程“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)
我还尝试了以下代码,得到了相同的结果:

    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>


非常感谢任何帮助或建议

此问题是由于类路径上有一个旧的、不兼容的JPA API副本造成的

具体而言:

  • 持久性:持久性api:1.0.2
与JPA 2.1 API的正确版本冲突:

  • 持久性:hibernate-jpa-2.1-api:1.0.0.Final

不幸的是,Maven 3仍然无法处理相同工件的重新分发,这有时是必要的。

您有什么版本的Gradle

我问,因为我有同样的错误发生在从
3.5
升级到
4.3
之后。相同的Hibernate版本(
5.2.9
),相同的Spring启动(
1.5.8
),但在Gradle
3.5中。
-正常,
4.3
失败

我已经测试过,最新版本对我来说运行良好
3.5.1
。我已经测试了从
4.0
4.4-rc-6
(目前最新版本)的版本


看起来像是hibernate和其他库的不兼容版本。请添加完整的stacktrace可能会帮助您感谢您的回复,我已经添加了完整的stacktrace。我已经看到了关于stackoverflow的另一个问题,但是他们使用了Spring,我在Java应用程序中没有使用Spring。请参见我在回答中提到的:org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.finalb,但是也可以在没有
org.hibernate
的情况下获得JPA2。当然,可以随意搜索另一个,但是API对于JPA标准定义的所有发行版都是一样的,完全相同。您是如何解决的?@RavishBhagdev请参阅此答案以了解有关解决问题的说明:
<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>
// 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'
}
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip