web-dev-qa-db-ja.com

spring4.2.1、hibernate5は抽象メソッドエラーを統合します

プロジェクトでspring-framework 4.2.1.BUILD-SNAPSHOTおよびhibernate 5.0.0.BETA2を宣言しましたが、AbstractMethodErrorが発生します。

スタックトレースは次のとおりです。

Java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.Java:83)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.Java:183)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.Java:123)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.Java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.Java:217)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.Java:276)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.Java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.Java:278)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:87)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.Java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.Java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.Java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.Java:180)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.Java:283)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.Java:173)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.Java:153)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.Java:128)
    at org.Apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.Java:203)
    at org.Apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.Java:155)
    at org.Apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.Java:103)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is Java.lang.AbstractMethodError
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:305)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:196)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1045)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:824)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:537)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:667)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.Java:342)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:273)
    at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.Java:102)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.Java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:116)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.Java:83)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.Java:183)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.Java:123)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.Java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.Java:217)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.Java:276)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.Java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.Java:278)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:87)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.Java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.Java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.Java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.Java:180)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.Java:283)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.Java:173)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.Java:153)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.Java:128)
    at org.Apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.Java:203)
    at org.Apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.Java:155)
    at org.Apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.Java:103)
Caused by: Java.lang.AbstractMethodError: null
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.Java:276)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.Java:444)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.Java:802)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.Java:60)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.Java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.Java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1574)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:305)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:196)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1045)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:824)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:537)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:667)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.Java:342)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:273)
    at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.Java:102)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.Java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:116)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.Java:83)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.Java:183)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.Java:123)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.Java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.Java:217)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.Java:276)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.Java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.Java:278)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:87)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.Java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.Java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.Java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.Java:180)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.Java:283)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.Java:173)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.Java:153)
    at org.Apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.Java:128)
    at org.Apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.Java:203)
    at org.Apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.Java:155)
    at org.Apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.Java:103)

私はorg.springframework.orm.hibernate5という名前のパッケージを検索して見つけましたが、spring-frameworkがhibernate5をサポートする必要があると思います。詳細 https://github.com/spring-projects/spring-framework/tree/v4.3.9.RELEASE/spring-orm-hibernate5/src/main/Java/org/springframework/orm/hibernate5 =

Hibernateのバージョンを他の5.0バージョンに変更しましたが、問題はまだあります。コードのバグなのでしょうか、それともSpringまたはHibernateなのでしょうか? hibernateのバージョンが4.3.10.Finalの場合、ソースは問題なく動作します。スタックトレースにすべての問題が表示されない場合があります。プロジェクトのソースは( https://github.com/zjnu-acm/judge2/commit/158e3de21e4bfc83b1fa863a649c982a9039f30b )で確認できます。ありがとう!

10
martian

これは、Hibernate 5と組み合わせたJadira Usertype 4.0.0.GA以前の問題です。Usertype5.0.0.GAで修正されています( http://jadira.sourceforge.net/changes-reportを参照)。 .html#a5.0.0.GA )。

私の場合、JodaTimeのサポートにUsertype 3.0.0.CR3を使用していました。 Java 8(JSR-310)タイムクラスまたはorg.jadira.usertype:usertype.extendedを使用しようとしていませんでした。

デバッグにより、タイプ「org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator」のインテグレーターをhibernateのSessionFactoryImplのintegratorObserversに追加しようとしたときに例外が発生することが示されています。

JSR-310を使用している場合、martianが示唆するようにhibernate-Java8モジュールを使用します。 JSR-310回ではなくJodaTimeを使用している場合、これは役に立ちません。比較的簡単な回避策は、使用するJodaTimeタイプごとにJPA 2.1 AttributeConverterを作成することです。

AttributeConvertersは、JSR-310タイプにも使用できます。これらには移植性があり、autoApply = trueを設定した場合、各エンティティフィールドに注釈を付ける必要がないという利点があります。

クラスの例:

https://github.com/marschall/threeten-jpa/tree/master/threeten-jpa/src/main/Java/com/github/marschall/threeten/jpa

20
drrob

Hibernate5には独自のJava 8クラスの実装があります。removeorg.jadira.usertype:usertype.extendおよびaddorg.hibernate:hibernate-Java8、問題はなくなります。

5
martian

以下のユーザータイプを使用して同じ問題を解決しました

    <dependency>
        <groupId>org.jadira.usertype</groupId>
        <artifactId>usertype.core</artifactId>
        <version>5.0.0.GA</version>
    </dependency>
0