IllegalArgumentException: At least one JPA metamodel must be present

starting with spring break, I got the following error:

org.springframework.beans.factory.BeanCreationException: error creating bean named 'jpaMappingContext': failed init method call; The nested exception is java.lang.IllegalArgumentException: at least one JPA metamodel must be present! at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1595) ~ [spring-beans-5.0.0.BUILD-SNAPSHOT.jar: 5.0.0.swork.ra beans.factory.suppory. AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java∗66) ~ [spring-beans-5.0.0.BUILD-SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.sworkwork.prf.AbstractAutowireCapableCutableeutableutaprebatecutableaputereate ) ~ [spring-beans-5.0.0.BUILD-SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.springframework.bee (AbstractBeanFactory.java:304) ~ [spring-beans-5.0.0.BUILD- SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.jpg) 230) ~ [spring-beans-5.0.0.BUILD-SNAPSHOT.jar: 5.0 .0.BUILD-SNAPSHOT] in org.springframework.beans.factory.suppo rt.AbstractBeanFactory.doGetBean (AbstractBeanFactory.javahaps00) ~ [spring-beans-5.0.0.BUILD-SN APSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.springframework.beans.factory.support.AbstractBeanFactory (AbstractBeanFactory.java:195) ~ [spring-beans-5.0.0.BUILD-SNAPSHOT.jar: 5.0.0 .BUILD-SNAPSHOT] in org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletan (DefaultListableBory) 725) ~ [spring-beans-5.0.0.BUILD-SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] org .springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:866) ~ [spring- -5.0.0.BUILD-SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.springframework.context.spptext .refresh (AbstractApplicationContext.java►42) ~ [spring-context-5.0.0.BUILD- SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh (EmbeddedWebApplicationContext. java: 122) ~ [spring-boot-2.0 .0.BUILD-SNAPSHOT.jar: 2.0.0.BUILD-SNAPSHOT] in org.springframework.boot.SpringApplication.refresh (SpringA pplication.java:736) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar: 2.0.0.BUILD-SNAPSHOT] in org.springframework.boot.SpringApplication.refreshContext (SpringApplication.javahaps69) [spring-boot -2.0.0.BUILD-SNAPSHOT.jar: 2.0.0.BUILD-SNAPSHOT] in org. springframework.boot.SpringApplication.run (SpringApplication.javahaps13) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar: 2.0.0.BUILD-SNAPSHOT] in org.springframework.boot.SpringApplication.run (SpringApplication. java: 1161) [spring-boot-2.0.0.BUILD-SNAPSHOT.jar: 2.0.0.BUILD-SNAPSHOT] in org.springframework.boot.SpringApplication.run (SpringApplication.java:1150) [spring-boot-2.0 .0.BUILD-SNAPSHOT.jar: 2.0.0.BUILD-SNAPSHOT] in com.java.app.QuickPollApplication.main (QuickPollApplication.java:14) [classes /: na] Called: java.lang.IllegalArgumentException: if should attend at least one JPA metamodel! in org.springframework.util.Assert.notEmpty (Assert.java:438) ~ [spring-core-5.0.0.BUILD-SNAPSHOT.jar: 5.0.0.BUILD-SNAPSHOT] in org.springframework.data.jpa. mapping.JpaMetamodelMappingContext. (JpaMetamodelMappingContext.java:52) ~ [spring-data-jpa-1.11.0.BUILD-SNAPSHOT.jar: na] in org.springframework.data.jpa.repository.config. java: 71) ~ [spring-data-jpa-1.11.0.BUILD-SNAPSHOT.jar: na] in org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance (JpaMetamodelMavaBextContext-1. 0.BUILD-SNAPSHOT.jar: na] at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet (AbstractFactoryBean.java:134) ~ [spring-beans-5.0.0.BUILD- SNAPSHOT.jar: 5.0.0 .BUILD-SNAPSHOT] in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java:1654) ~ [spring ans-5.0.0.0UUILD-SNAPSHOTHj.jar: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.j.0: BeanFactory.j.0: 91: spring91) -159191.BUILD-SNAPSHOT.jar: 5.0.0PSUOT] 16 total frames omitted

with the following code

@SpringBootApplication @RestController public class QuickPollApplication { public static void main(String[] args) { SpringApplication.run(QuickPollApplication.class, args); } @RequestMapping(value = "/test", method = RequestMethod.GET) public String testRest() { return "rest tested"; } 

and below my pom.xml

UTF-8 UTF-8 1.8

  <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> 

Please help me. I do not know how to solve this error

+17
source share
4 answers

You added

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> 

in your pom.xml.

Spring boot will attempt to automatically create an entity factory for JPA, but you have not defined anything regarding JPA models.

Try deleting it to check what you have already done.

After that you can check the tutorial using spring-data-starter-jpa like this guy

+24
source

I fixed this by installing a newer version of Hibernate.

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </exclusion> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.10.Final</version> </dependency> 

You can find a fully working example here: https://github.com/zobarov/ptc-task-executor

+8
source

You can also disable Spring Data JPA repository support by excluding the following automatic configuration class (for example, in the @EnableAutoConfiguration or @SpringBootApplication )

 org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration 

For instance:

 @EnableAutoConfiguration(exclude = JpaRepositoriesAutoConfiguration.class) 
+1
source

It worked for me.

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </exclusion> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.10.Final</version> </dependency> 
0
source

Source: https://habr.com/ru/post/1012559/


All Articles