{"record":{"id":"9615dd82d7e2bcae","repo":"hibernate/hibernate-orm","slug":"given-value-s-did-not-match-expected-identifier","errorCode":null,"errorMessage":"Given value '%s' did not match expected identifier type '%s' of entity '%s'","messagePattern":"Given value '(.+?)' did not match expected identifier type '(.+?)' of entity '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java","lineNumber":38,"sourceCode":"import org.hibernate.persister.entity.EntityPersister;\nimport org.hibernate.type.descriptor.java.CoercionException;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\n/**\n * @author Steve Ebersole\n */\npublic class Helper {\n\tpublic static final FindOption[] NO_OPTIONS = new FindOption[0];\n\n\tpublic static Object coerceId(EntityPersister entityPersister, Object id, SessionFactoryImplementor factory) {\n\t\tfinal var identifierMapping = entityPersister.getIdentifierMapping();\n\t\tif ( isLoadByIdComplianceEnabled( factory ) ) {\n\t\t\tfinal var javaType = identifierMapping.getJavaType();\n\t\t\tif ( !identifierMapping.isVirtual() && !javaType.isInstance( id ) ) {\n\t\t\t\t// per expectation of EntityHandler#find / EntityHandler#get\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Given value '%s' did not match expected identifier type '%s' of entity '%s'\"\n\t\t\t\t\t\t\t\t.formatted( id, javaType.getTypeName(), entityPersister.getEntityName() ) );\n\t\t\t}\n\t\t\treturn id;\n\t\t}\n\t\telse {\n\t\t\ttry {\n\t\t\t\treturn identifierMapping.isVirtual()\n\t\t\t\t\t\t? id // special case for a class with an @IdClass\n\t\t\t\t\t\t: identifierMapping.getJavaType().coerce( id );\n\t\t\t}\n\t\t\tcatch ( Exception e ) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Argument '%s' could not be converted to the identifier type of entity '%s': %s\"\n\t\t\t\t\t\t\t\t.formatted( id, entityPersister.getEntityName(), e.getMessage() ),\n\t\t\t\t\t\te\n\t\t\t\t);\n\t\t\t}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java#L20-L56","documentation":"Error \"Given value '%s' did not match expected identifier type '%s' of entity '%s'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an id of the entity's declared identifier type (e.g. Long vs Integer); convert the value before calling find."],"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"}