0

In one of my maven project dependency graph of hibernate-core is as follows:

    [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

I am getting error as follows:

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

Regarding same, I followed this posts: Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; and NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index. I am not getting any clue regarding how to fix this.

2
  • Is there another jpa dependency on the classpath? Or any other jar that conains a class javax.persistence.Table? Commented Apr 28, 2020 at 15:17
  • Yes @GreyFairer I have. I have org.springframework.data:spring-data-jpa:jar:2.2.4.RELEASE:compile and javax.persistence:javax.persistence-api:jar:2.2:compile. I have updated the post accordingly. Commented Apr 28, 2020 at 15:19

2 Answers 2

0

If you follow the dependencies, you will probably find something like:

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

So that's probably the one with the older javax.persistence.Table class.

I'm not sure if Spring Data is ready for JPA 2.2.

If you look at the pom.xml for spring-data-jpa:2.2.4.RELEASE, it depends on hibernate 5.2.17.Final, and they haven't updated yet.

So I would stick to the hibernate 5.2.x series.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah @GryFairer, I am trying to get rid of this dependency org.springframework.data:spring-data-jpa:jar:2.2.4.RELEASE:compile, but I am not able to even after putting in exclusion block inside hibernate-core in pom.xml
Yeah, exclusion blocks are terrible to work with. But I think if you lower the version for hibernate to 5.2.17.Final or 5.2.18.Final, everything should work without needing exclusion blocks.
0

I resolved the issue. This was because of adding Java EE6 jar as an external dependency through Intellij, which I had done while setting up the project. As soon as I removed this, it started working. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.