Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if there is a No identifier specified for en error in SpringBoot JPA?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the SpringBoot JPA No identifier specified for en error how to do, the article is very detailed, has a certain reference value, interested friends must read it!

Error in JPA description of No identifier specified for en problem

The startup project was not successful and an error was reported as follows:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2019-03-17 13 org.springframework.boot.SpringApplication.reportFailure:858 19V 24.391 | main | ERROR | org.springframework.boot.SpringApplication.reportFailure:858 | Application run failed

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 org.hibernate.AnnotationException: No identifier specified for entity: com.xxx.domain.Earnings

At org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1745)

At org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:576)

At org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:498)

At org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)

At org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)

At org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)

At org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)

At org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1083)

At org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:853)

At org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:546)

At org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:142)

At org.springframework.boot.SpringApplication.refresh (SpringApplication.java:775)

At org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:397)

At org.springframework.boot.SpringApplication.run (SpringApplication.java:316)

At org.springframework.boot.SpringApplication.run (SpringApplication.java:1260)

At org.springframework.boot.SpringApplication.run (SpringApplication.java:1248)

At com.xxx.YoufanApplication.main (YoufanApplication.java:21)

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.xxx.domain.Earnings

At org.hibernate.cfg.InheritanceState.determineDefaultAccessType (InheritanceState.java:266)

At org.hibernate.cfg.InheritanceState.getElementsToProcess (InheritanceState.java:211)

At org.hibernate.cfg.AnnotationBinder.bindClass (AnnotationBinder.java:778)

At org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies (AnnotationMetadataSourceProcessorImpl.java:250)

At org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies (MetadataBuildingProcess.java:231)

At org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:274)

At org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:904)

At org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:935)

At org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory (SpringHibernateJpaPersistenceProvider.java:57)

At org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory (LocalContainerEntityManagerFactoryBean.java:365)

At org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory (AbstractEntityManagerFactoryBean.java:390)

At org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet (AbstractEntityManagerFactoryBean.java:377)

At org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet (LocalContainerEntityManagerFactoryBean.java:341)

At org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java:1804)

At org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1741)

... 16 common frames omitted

Disconnected from the target VM, address: '127.0.0.1 transport:' socket'

Process finished with exit code 1

First of all, find the core error description:

Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.xxx.domain.Earnings

Cause of the problem

Using javax.persistence.Entity for annotation in the entity class com.xxx.domain.Earnings will automatically perform the DDL operation of the table.

When using hibernate's mapping table, the entity class must have a primary key, otherwise this exception will be reported: No identifier specified for entity

Solution import javax.persistence.*;@Entitypublic class Earnings {@ Id @ GeneratedValue (strategy = GenerationType.AUTO) Long id; / /...}

After annotating with @ javax.persistence.Id, the problem is resolved.

No identifier specified for entity: XXXX error

The following error was reported while running the project:

By: org.hibernate.AnnotationException: No identifier specified for entity: com.example1.demo1.Entity.User

At org.hibernate.cfg.InheritanceState.determineDefaultAccessType (InheritanceState.java:266) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.cfg.InheritanceState.getElementsToProcess (InheritanceState.java:211) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.cfg.AnnotationBinder.bindClass (AnnotationBinder.java:731) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies (AnnotationMetadataSourceProcessorImpl.java:249) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies (MetadataBuildingProcess.java:222) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:265) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:861) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

At org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:888) ~ [hibernate-core-5.2.17.Final.jar:5.2.17.Final]

Causes and Solutions

This is because the @ Id annotation was not added to the entity's getID method, but it was added after a check, and the final solution is as follows:

1. Add the text note before the method of the database table corresponding entity (entity.java): getId ()

@ Id@GeneratedValue (strategy= GenerationType.AUTO)

two。 It's because the id comments lead to the wrong package.

Wrong package path:

Import org.springframework.data.annotation.Id

The correct package path:

Import javax.persistence.Id; above is all the content of this article "what to do if there is an No identifier specified for en error in SpringBoot JPA". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report