在我的hibernate-core的Maven项目依赖图中,如下所示:
[INFO] +- org.hibernate:hibernate-core:jar:5.4.10.Final:compile
[INFO] | +- (org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile - version managed from 3.3.2.Final; omitted for duplicate)
[INFO] | +- javax.persistence:javax.persistence-api:jar:2.2:compile
+- (org.hibernate:hibernate-core:jar:5.4.10.Final:compile - omitted for duplicate)
[INFO] | +- org.springframework.data:spring-data-jpa:jar:2.2.4.RELEASE:compile
我收到如下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at com.salesforce.sconems.abstractions.SconeApp.run(SconeApp.java:118)
at com.salesforce.sconems.abstractions.SconeApp.run(SconeApp.java:163)
at com.salesforce.tm.ThreatmodelServiceService.main(ThreatmodelServiceService.java:23)
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:1236)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:836)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:254)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:230)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:273)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1202)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1233)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 16 common frames omitted
关于此,我关注了这篇文章:Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;和NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index。我没有任何有关如何解决此问题的线索。
答案 0 :(得分:0)
如果您遵循依赖关系,您可能会发现类似以下内容的东西:
spring-data-jpa:2.2.4.RELEASE
-> org.hibernate:hibernate-core:5.2.17.Final(optional)
-> org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
所以这可能是带有较旧的javax.persistence.Table类的那个。
我不确定Spring Data是否已准备好用于JPA 2.2。
如果您查看spring-data-jpa:2.2.4.RELEASE的pom.xml,它取决于休眠的5.2.17.Final,并且尚未更新。
所以我会坚持使用休眠5.2.x系列。
答案 1 :(得分:0)
我解决了这个问题。这是因为通过Intellij将Java EE6 jar添加为外部依赖项,这是我在设置项目时所做的。我一删除它,它就开始工作。谢谢。