启动项目未成功,报错如下:
error starting applicationcontext. to display the conditions report re-run your application with ‘debug’ enabled.
2019-03-17 13:19: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 or鲁滨孙飘流记g.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.rvlet.context.rvletwebrverapplicationcontext.refresh(rvletwebrverapplicationcontext.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)
caud 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.procesntityhierarchies(annotationmetadatasourceprocessorimpl.java:250)
at org.hibernate.boot.model.process.spi.metadatabuildingprocess$1.procesntityhierarchies(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.afterpropertiest(abstractentitymanagerfactorybean.java:377)
at org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.afterpropertiest(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:50341’, transport: ‘socket’process finished with exit code 1
首先从其中找到核心错误描述:
invocation of init method failed; nested exception is org.hibernate.annotationexception: no identifier specified for entity: com.xxx.domain.earnings
在实体类com.xxx.domain.earnings使用javax.persistence.entity进行注解就会自动进行表的ddl操作
使用hibernate的映射表的时候entity类是必须要主键的,否则就会报出这个异常:no identifier specified for entity
import javax.persistence.*;@entitypublic class earnings { @id @generatedvalue(strategy = generationtype.auto) long id; // ...}
使用@javax.persistence.id进行注解后,问题解决。
在运行项目的时候报了下面的错误:
by: org.hibernate.annotationexception: no identifier specified for entity: com.example1.demo1.entity.ur
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.procesntityhierarchies(annotationmetadatasourceprocessorimpl.java:249) ~[hibernate-core-5.2.17.final.jar:5.2.17.final]
at org.hibernate.boot.model.process.spi.metadatabuildingprocess$1.procesntityhierarchies(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.intern儿童网球al.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:888) ~[hibernate-core-5.2.17.final.jar:5.2.17.final]
这是因为在实体的getid方法上没有加上此@id注解,但是检查了一次确实加上了,最后的解决办法如下:
1.在数据库表对应实体(entity.java)的方法:getid()前加上该段文字注解
@id@generatedvalue(strategy= generationtype.auto)
2.是因为id注解引错了包
错误的包路径:
import org.springframework.data.annotation.id;
正确的包路径:
import javax.persistence.id;
以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。
本文发布于:2023-04-06 03:08:31,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/28ff06914c2f129cc58c8a9f28719268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:SpringBoot JPA出现错误:No identifier specified for en解决方案.doc
本文 PDF 下载地址:SpringBoot JPA出现错误:No identifier specified for en解决方案.pdf
留言与评论(共有 0 条评论) |