{"record":{"id":"e1a182ed22256675","repo":"hibernate/hibernate-orm","slug":"attribute-memberdetails-getname-is-dec","errorCode":null,"errorMessage":"Attribute '\" + memberDetails.getName() + \"' is declared by '\" + memberDetails.getDeclaringType().getName() + \"' and may not be redeclared as an '@Id' or '@EmbeddedId' by '\" + property.getDeclaringType().getName() + \"'","messagePattern":"Attribute '\" \\+ memberDetails\\.getName\\(\\) \\+ \"' is declared by '\" \\+ memberDetails\\.getDeclaringType\\(\\)\\.getName\\(\\) \\+ \"' and may not be redeclared as an '@Id' or '@EmbeddedId' by '\" \\+ property\\.getDeclaringType\\(\\)\\.getName\\(\\) \\+ \"'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java","lineNumber":786,"sourceCode":"\t\t\t\t\t\t|| !property.getMetaAnnotated( IdGeneratorType.class, context ).isEmpty() ) {\n\t\t\t\t\t//TODO: it would be nice to allow a root @Entity to override an\n\t\t\t\t\t//      @Id field declared by a @MappedSuperclass and change the\n\t\t\t\t\t//      generator, but for now we don't seem to be able to detect\n\t\t\t\t\t//      that case here\n\t\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\t\"Attribute '\" + memberDetails.getName()\n\t\t\t\t\t\t\t+ \"' is declared as an '@Id' or '@EmbeddedId' property by '\"\n\t\t\t\t\t\t\t+ memberDetails.getDeclaringType().getName()\n\t\t\t\t\t\t\t+ \"' and so '\" + property.getDeclaringType().getName()\n\t\t\t\t\t\t\t+ \"' may not respecify the generation strategy\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t//TODO: it would be nice to allow a root @Entity to override a\n\t\t\t\t//      field declared by a @MappedSuperclass, redeclaring it\n\t\t\t\t//      as an @Id field, but for now we don't seem to be able\n\t\t\t\t//      to detect that case here\n\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\"Attribute '\" + memberDetails.getName()\n\t\t\t\t\t\t+ \"' is declared by '\" + memberDetails.getDeclaringType().getName()\n\t\t\t\t\t\t+ \"' and may not be redeclared as an '@Id' or '@EmbeddedId' by '\"\n\t\t\t\t\t\t+ property.getDeclaringType().getName() + \"'\" );\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic boolean hasIdAnnotation(MemberDetails element) {\n\t\treturn isSimpleId( element ) || isEmbeddedId( element );\n\t}\n\n\t/**\n\t * Process annotation of a particular property or field.\n\t */\n\tpublic static void processElementAnnotations(\n\t\t\tPropertyHolder propertyHolder,\n\t\t\tNullability nullability,","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java#L768-L804","documentation":"The mirror case of the generation-strategy error: an attribute that a superclass declares as a plain (non-id) property is redeclared in a subclass as @Id or @EmbeddedId. Hibernate's id-property bookkeeping cannot promote an inherited attribute to identifier status, so AnnotationException is thrown while reconciling id properties.","triggerScenarios":"@MappedSuperclass declares private String code; the subclass adds @Id on its overriding code field/getter; hierarchies where a subtype was supposed to own its primary key but the field already exists higher up.","commonSituations":"Refactoring single-table hierarchies so a subtype becomes independently identifiable; merging unrelated entities under a common base class; generated code that adds @Id to every concrete class's fields.","solutions":["Remove @Id/@EmbeddedId from the subclass redeclaration.","If the subtype truly needs its own identity, remove the conflicting attribute from the superclass and declare the @Id field on the subclass (or split the hierarchy).","Restructure so the identifier is declared at one level only: either the shared root (@MappedSuperclass/@Entity) or the concrete entity — never promoted from below."],"exampleFix":"// before\n@MappedSuperclass\npublic abstract class Base {\n    protected String code;\n}\n@Entity\npublic class Product extends Base {\n    @Override\n    @Id   // promoting an inherited plain attribute => rejected\n    public String getCode() { return code; }\n}\n\n// after: declare the id at one level\n@MappedSuperclass\npublic abstract class Base { /* no 'code' here */ }\n@Entity\npublic class Product extends Base {\n    @Id\n    private String code;\n}","handlingStrategy":"validation","validationCode":"// A subclass may not promote an inherited plain attribute to @Id\nfor (Class<?> entity : annotatedClasses) {\n    Class<?> sup = entity.getSuperclass();\n    while (sup != null && (sup.isAnnotationPresent(MappedSuperclass.class) || sup.isAnnotationPresent(Entity.class))) {\n        for (Field own : entity.getDeclaredFields()) {\n            if (!own.isAnnotationPresent(Id.class)) continue;\n            try {\n                Field supF = sup.getDeclaredField(own.getName());\n                if (!supF.isAnnotationPresent(Id.class)) {\n                    throw new IllegalStateException(entity.getName() + \" redeclares inherited attribute \" + own.getName() + \" as @Id\");\n                }\n            } catch (NoSuchFieldException ignored) { }\n        }\n        sup = sup.getSuperclass();\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    SessionFactory sf = cfg.buildSessionFactory();\n} catch (AnnotationException e) {\n    throw new IllegalStateException(\"Id redeclaration conflict: \" + e.getMessage(), e);\n}","preventionTips":["Declare identifiers at a single hierarchy level","When introducing @Id on a subclass field, remove the inherited attribute from the superclass"],"tags":["hibernate","jpa","id","mapped-superclass","inheritance","annotation-conflict","bootstrap"],"backgroundTag":"inherited-id-override-conflict","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}