{"record":{"id":"1f622eeb4c92e7dd","repo":"hibernate/hibernate-orm","slug":"member-memberdetails-getname-of-embedd","errorCode":null,"errorMessage":"Member '\" + memberDetails.getName() + \"' of embeddable class '\" + propertyHolder.getClassName() + \"' is annotated '@Id'","messagePattern":"Member '\" \\+ memberDetails\\.getName\\(\\) \\+ \"' of embeddable class '\" \\+ propertyHolder\\.getClassName\\(\\) \\+ \"' is annotated '@Id'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java","lineNumber":869,"sourceCode":"\t\t}\n\t}\n\n\tprivate static void buildProperty(\n\t\t\tPropertyHolder propertyHolder,\n\t\t\tNullability nullability,\n\t\t\tPropertyData inferredData,\n\t\t\tEntityBinder entityBinder,\n\t\t\tboolean isIdentifierMapper,\n\t\t\tboolean isComponentEmbedded,\n\t\t\tboolean inSecondPass,\n\t\t\tMetadataBuildingContext context,\n\t\t\tMap<ClassDetails, InheritanceState> inheritanceStatePerClass) {\n\n\t\tfinal var memberDetails = inferredData.getAttributeMember();\n\n\t\tif ( isPropertyOfRegularEmbeddable( propertyHolder, isComponentEmbedded )\n\t\t\t\t&& isSimpleId( memberDetails ) ) {\n\t\t\tthrow new AnnotationException(\"Member '\" + memberDetails.getName()\n\t\t\t\t\t+ \"' of embeddable class '\" + propertyHolder.getClassName() + \"' is annotated '@Id'\");\n\t\t}\n\n\t\tfinal var attributeTypeDetails =\n\t\t\t\tmemberDetails.isPlural()\n\t\t\t\t\t\t? memberDetails.getType()\n\t\t\t\t\t\t: inferredData.getClassOrElementType();\n\n\t\tfinal var propertyBinder = propertyBinder(\n\t\t\t\tpropertyHolder,\n\t\t\t\tinferredData,\n\t\t\t\tentityBinder,\n\t\t\t\tisIdentifierMapper,\n\t\t\t\tcontext,\n\t\t\t\tinheritanceStatePerClass,\n\t\t\t\tattributeTypeDetails\n\t\t);\n","sourceCodeStart":851,"sourceCodeEnd":887,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java#L851-L887","documentation":"When an embeddable is used as a regular @Embedded (not as an @EmbeddedId aggregate), none of its members may carry @Id — identifiers may only appear at the entity level or inside an @EmbeddedId component. PropertyBinder detects the stray @Id while binding the property and fails bootstrap.","triggerScenarios":"A class reused both as @EmbeddedId component and as plain @Embeddable, with @Id left inside; an embeddable copied from an id-class template; converting an @EmbeddedId to @Embedded without removing the @Id from the embedded field.","commonSituations":"Sharing one embeddable class between composite-id usage and regular embedded usage; refactoring from composite keys to surrogate keys; scaffolding tools that generate @Id on embeddable members.","solutions":["Remove @Id from the member of the embeddable when the class is used via @Embedded.","If both usages are needed, split into two classes: one clean embeddable, one @EmbeddedId-specific component.","If the field really is the entity's identity, use @EmbeddedId on the entity property instead of @Embedded."],"exampleFix":"// before\n@Embeddable\npublic class Money {\n    @Id            // rejected in a regular embeddable\n    private Long id;\n    private BigDecimal amount;\n}\n@Entity\npublic class Deal {\n    @Embedded\n    private Money price;\n}\n\n// after\n@Embeddable\npublic class Money {\n    private BigDecimal amount;\n}\n@Entity\npublic class Deal {\n    @Id @GeneratedValue\n    private Long id;\n    @Embedded\n    private Money price;\n}","handlingStrategy":"validation","validationCode":"// Regular embeddables must not contain @Id members\nfor (Class<?> cls : annotatedClasses) {\n    if (!cls.isAnnotationPresent(Embeddable.class)) continue;\n    boolean usedAsEmbeddedId = annotatedClasses.stream()\n            .flatMap(e -> Stream.of(e.getDeclaredFields()))\n            .filter(f -> f.isAnnotationPresent(Embedded.class))\n            .anyMatch(f -> f.getType().equals(cls));\n    if (usedAsEmbeddedId) continue;\n    for (Field f : cls.getDeclaredFields()) {\n        if (f.isAnnotationPresent(Id.class)) {\n            throw new IllegalStateException(\"Regular embeddable \" + cls.getName() + \" has @Id member \" + f.getName());\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    SessionFactory sf = cfg.buildSessionFactory();\n} catch (AnnotationException e) {\n    throw new IllegalStateException(\"Embeddable contains @Id: \" + e.getMessage(), e);\n}","preventionTips":["Don't reuse one embeddable class for both @Embedded and @EmbeddedId roles","Strip @Id from embeddable members when converting @EmbeddedId to @Embedded"],"tags":["hibernate","jpa","embeddable","embedded","id","annotation-misuse","bootstrap"],"backgroundTag":"embeddable-id-misplaced","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}