An entity cannot be annotated with both @Entity and @MappedSuperclass




Asked on May 20, 2013
Hi I am new to Hibernate, got an error , help me to debug,

Caused by: org.hibernate.AnnotationException: An entity cannot be annotated with both @Entity and @MappedSuperclass:
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:510)
    at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)



Replied on May 20, 2013
@Entity and @MappedSuperclass can not be used together.  @Entity maps a class to a database table where as @MappedSuperclass keeps common attribute as super class. Use any one of them according to requirement.


Write Answer










©2024 concretepage.com | Privacy Policy | Contact Us