您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发
【原】JPA报错“No identifier specified for entity”的原因
不忘初心 2019-03-23 围观() 评论() 点赞() 【JAVA开发】
简介:之前在SSH框架中,用过Hibernate这个ORM框架,之后一直都是用的是Mybatis,最近公司里面使用springboot的框架中集成了JPA,虽然我觉着各种不好,但是讲真的还是挺好用,跟Hibernate相比还要简单,基本上都不用自己怎么写查询,今天在使用的时候手一抖,少复制了点儿代码,直接导致启动时报了一个错误“No identifier specified for entity”。20
之前在SSH框架中,用过Hibernate这个ORM框架,之后一直都是用的是Mybatis,最近公司里面使用springboot的框架中集成了JPA,虽然我觉着各种不好,但是讲真的还是挺好用,跟Hibernate相比还要简单,基本上都不用自己怎么写查询,今天在使用的时候手一抖,少复制了点儿代码,直接导致启动时报了一个错误“No identifier specified for entity”。
2019-03-22 13:49:05,418 ERROR SpringApplication: Application startup failed
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 org.hibernate.AnnotationException: No identifier specified for entity: com.wolffy.jpa.dataobject.GooglePushLogDO
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:131)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.wolffy.jpa.dataobject.GooglePushLogDO
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:265)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:717)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
... 29 common frames omitted
由于这种代码都是粘贴复制之前写过的,Java类代码如下:
package com.wolffy.jpa.dataobject;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Entity
@Table(name = "google_push_log")
@Getter
@Setter
public class GooglePushLogDO {
private Long id;
private String api_key;
private String apiUrl;
private String apiRequest;
private String apiResponse;
@Column(name = "`from`")
private String from;
private Date createTime;
}
仔细检查之后,发现导致启动失败的原因,是因为在主键ID上面少了两个注解:@Id、@GeneratedValue(strategy = GenerationType.AUTO)
package com.wolffy.jpa.dataobject;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Entity
@Table(name = "google_push_log")
@Getter
@Setter
public class GooglePushLogDO {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String api_key;
private String apiUrl;
private String apiRequest;
private String apiResponse;
@Column(name = "`from`")
private String from;
private Date createTime;
}
@Id:标识id字段为主键;
@GeneratedValue(strategy = GenerationType.AUTO):设置主键ID自增策略;
看完文章,有任何疑问,请加入群聊一起交流!!!
很赞哦! ()
相关文章
- springboot整合jpa启动报错'hibernate.dialect' not set
- Oracle的表字段带有双引号,在Jpa中使用sum等函数时报错“标识符或文字无效”
- springboot项目中连接oracle时需要带上模式前缀
- springboot jpa查询oracle提示“ORA-01747: user.table.column, table.column 或列说明无效”
- springboot jpa配置双数据源报错“Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set”
- springboot jpa报错“org.hibernate.LazyInitializationException: could not initialize proxy”
- springboot jpa启动报错“org.hibernate.AnnotationException: No identifier specified for entity”
- springboot jpa启动报错“java.lang.IllegalArgumentException: Not a managed type: class xxx”
标签云
猜你喜欢
- IntelliJ IDEA 2019.2已经可以利用补丁永久破解激活了
- IntelliJ IDEA 2019.3利用补丁永久破解激活教程
- IntelliJ IDEA高版本最灵活的永久破解激活方法(含插件激活,时长你说了算)
- Jetbrains全家桶基于ja-netfilter的最新破解激活详细图文教程
- IntelliJ IDEA 2022.1永久破解激活教程(亲测可用,持续更新)
- 分享几个正版 IntelliJ IDEA 激活码(破解码、注册码),亲测可用,持续更新
- ja-netfilter到底需不需要mymap,2021.3.2版本激活失效?
- 如何激活idea2022.1及以上版本中的插件(亲测可用)
- 【史上最全】IntelliJ IDEA最新2022.1版本安装和激活视频教学(含插件)
- IntelliJ IDEA 2022.2 版本最新2099年永久激活方法,亲测可用,也可以开启新UI了。
站点信息
- 网站程序:spring + freemarker
- 主题模板:《今夕何夕》
- 文章统计:篇文章
- 标签管理:标签云
- 微信公众号:扫描二维码,关注我们