{"record":{"id":"5624a67d2adf109d","repo":"hibernate/hibernate-orm","slug":"property-propertyname-in-idclass-declaringc","errorCode":null,"errorMessage":"Property '<propertyName>' in @IdClass '<declaringClass>' doesn't match type in entity class '<propertyType>' (expected '<entityPropertyTypeName>' but was '<idPropertyTypeName>')","messagePattern":"Property '<propertyName>' in @IdClass '<declaringClass>' doesn't match type in entity class '<propertyType>' \\(expected '<entityPropertyTypeName>' but was '<idPropertyTypeName>'\\)","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java","lineNumber":960,"sourceCode":"\tprivate static boolean checkIdProperty(\n\t\t\tPropertyHolder propertyHolder, PropertyData baseInferredData,\n\t\t\tPropertyData entityPropertyData, PropertyData idClassPropertyData) {\n\t\tif ( entityPropertyData == null ) {\n\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\"Property '\" + getPath( propertyHolder, idClassPropertyData )\n\t\t\t\t\t+ \"' belongs to an '@IdClass' but has no matching property in entity class '\"\n\t\t\t\t\t+ baseInferredData.getPropertyType().getName()\n\t\t\t\t\t+ \"' (every property of the '@IdClass' must have a corresponding persistent property in the '@Entity' class)\"\n\t\t\t);\n\t\t}\n\t\telse if ( deferIdProperty( entityPropertyData, idClassPropertyData ) ) {\n\t\t\treturn false;\n\t\t}\n\t\telse {\n\t\t\tfinal String idPropertyTypeName = idClassPropertyData.getTypeName();\n\t\t\tfinal String entityPropertyTypeName = entityPropertyData.getTypeName();\n\t\t\tif ( !hasCompatibleType( idPropertyTypeName, entityPropertyTypeName ) ) {\n\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\"Property '\" + idClassPropertyData.getPropertyName()\n\t\t\t\t\t\t+ \"' in @IdClass '\" + idClassPropertyData.getDeclaringClass().getName()\n\t\t\t\t\t\t+ \"' doesn't match type in entity class '\" + baseInferredData.getPropertyType().getName()\n\t\t\t\t\t\t+ \"' (expected '\" + entityPropertyTypeName + \"' but was '\" + idPropertyTypeName + \"')\"\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t//don't replace here as we need to use the actual original return type\n\t//the annotation overriding will be dealt with by a mechanism similar to @MapsId\n\tprivate static boolean deferIdProperty(PropertyData entityPropertyData, PropertyData idClassPropertyData) {\n\t\treturn hasToOneAnnotation( entityPropertyData.getAttributeMember() )\n\t\t\t&& !entityPropertyData.getClassOrElementType().equals( idClassPropertyData.getClassOrElementType() );\n\t}\n\n\tstatic boolean hasCompatibleType(String typeNameInIdClass, String typeNameInEntityClass) {","sourceCodeStart":942,"sourceCodeEnd":978,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java#L942-L978","documentation":"Error \"Property '<propertyName>' in @IdClass '<declaringClass>' doesn't match type in entity class '<propertyType>' (expected '<entityPropertyTypeName>' but was '<idPropertyTypeName>')\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A composite identifier mapping (@IdClass/@EmbeddedId/@MapsId) does not match the entity's persistent properties.","commonSituations":"Composite primary keys where the id class properties, their types, or @MapsId values drift out of sync with the entity, or an embeddable with inheritance is reused as an id.","solutions":["Change the @IdClass property type to match the entity property type exactly."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}