{"record":{"id":"bf3b685928ac7d45","repo":"hibernate/hibernate-orm","slug":"argument-s-could-not-be-converted-to-the-identi","errorCode":null,"errorMessage":"Argument '%s' could not be converted to the identifier type of entity '%s': %s","messagePattern":"Argument '(.+?)' could not be converted to the 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":51,"sourceCode":"\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}\n\t\t}\n\t}\n\n\tpublic static Object[] coerceIds(EntityPersister entityPersister, List<?> keys, SharedSessionContractImplementor session) {\n\t\tObject[] ids = null;\n\t\tfinal int size = keys.size();\n\t\tfor ( int i = 0; i < size; i++ ) {\n\t\t\tfinal var factory = session.getFactory();\n\t\t\tfinal Object key = keys.get( i );\n\t\t\tfinal Object coerced = coerceId( entityPersister, key, factory );\n\t\t\tif ( coerced != key ) {\n\t\t\t\tif ( ids == null ) {\n\t\t\t\t\tids = new Object[size];","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java#L33-L69","documentation":"Error \"Argument '%s' could not be converted to the identifier type of entity '%s': %s\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the argument to the entity identifier type (e.g. Long.valueOf) before calling, or fix the entity's id type mapping."],"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"}