An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.Use
Posted itiande
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.Use相关的知识,希望对你有一定的参考价值。
项目问SpringDataJpa项目,在运行的过程中出现的以下错误:
Caused by: org.hibernate.AnnotationException: An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.User at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:493) ~[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] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.0.6.RELEASE.jar:5.0.6.RELEASE]
解决办法:
在实例类上删除掉@MappedSuperclass注解方可解决此错误,但是又会出现下面的错误:
No identifier specified for entity: com.example1.demo1.Entity.User
这个错误的原因是ID主键没有声明,程序找不到主键才报的错误。
但是有些情况下,删除这个注解也有可能会报其他的异常,请参考下面这篇博客:
https://www.cnblogs.com/itiande/p/9139161.html
以上是关于An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.Use的主要内容,如果未能解决你的问题,请参考以下文章
The import javax.servlet.annotation cannot be resolved怎么解决
An entry point cannot be marked with the 'async' modifier
TypeError: 'list' object cannot be interpreted as an integer
jsp页面老提示Multiple annotations found at this line: - javax.servlet.jsp.JspException cannot be resolve(
eclipse报错:Multiple annotations found at this line: - String cannot be resolved to a type解决方法实测
java.lang.ClassCastException: xut.bookshop.entity.User_$$_javassist_3 cannot be cast to javassist.ut