web-dev-qa-db-fra.com

spring4.2.1, hibernate5 integrer l'erreur de méthode abstraite

Je déclare spring-framework 4.2.1.BUILD-SNAPSHOT et hibernate 5.0.0.BETA2 dans mon projet, mais j'obtiens un AbstractMethodError.

Voici la trace de la pile:

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)

J'ai cherché et trouvé un paquet nommé org.springframework.orm.hibernate5, je suppose que spring-framework doit prendre en charge hibernate5 maintenant. Détail https://github.com/spring-projects/spring-framework/tree/v4.3.9.RELEASE/spring-orm-hibernate5/src/main/Java/org/springframework/orm/hibernate5

Je remplace la version de Hibernate par une autre version 5.0, mais le problème persiste. Devrait-il s’agir d’un bogue de mon code, de mon printemps ou de ma veille prolongée? Mon source fonctionne correctement lorsque la version de veille prolongée est 4.3.10.Final. Peut-être que la trace de la pile ne montre pas tous les problèmes, vous pouvez afficher le code source de mon projet via ( https://github.com/zjnu -acm/judge2/commit/158e3de21e4bfc83b1fa863a649c982a9039f30b ) Quelqu'un peut-il m'aider? Merci!

8
martian

Ceci est un problème avec Jadira Usertype 4.0.0.GA et les versions antérieures, associé à Hibernate 5. Il est résolu dans Usertype 5.0.0.GA (voir http://jadira.sourceforge.net/changes-report.html # a5.0.0.GA ).

Dans mon cas, j'utilisais le support Usertype 3.0.0.CR3 for JodaTime. Je n'essayais pas d'utiliser les classes de temps Java 8 (JSR-310) ni org.jadira.usertype: usertype.extended.

Le débogage montre que l'exception se produit lors de l'ajout d'un intégrateur de type "org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator" à l'intégrateurObservers de SessionFactoryImpl de hibernate.

Si vous utilisez JSR-310, utilisez le module hibernate-Java8, comme le suggère martian. Si vous utilisez JodaTime et non pas JSR-310, cela ne vous aidera pas. Une solution relativement simple consiste à créer un AttributeConverter JPA 2.1 pour chaque type JodaTime utilisé.

AttributeConverters peut également être utilisé pour les types JSR-310. Ils ont l'avantage d'être portables et qu'il n'est pas nécessaire d'annoter chaque champ d'entité si vous définissez autoApply = true. 

Exemple de cours:

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

20
drrob

Il semble que usertype soit à blâmer, usertype 4.0.0.GA ne supporte pas hibernate5, car hibernate5 dispose de ses propres implémentations des classes Java 8. remove org.jadira.usertype:usertype.extend et add org.hibernate:hibernate-Java8, du problème sera parti.

5
martian

J'ai eu le même problème résolu en utilisant ci-dessous usertype

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