{"record":{"id":"0f0b15fe4e35d87d","repo":"hibernate/hibernate-orm","slug":"supplied-id-had-wrong-type-entity-persister-ge","errorCode":null,"errorMessage":"Supplied id had wrong type: entity '${persister.getEntityName()}' has id type '${idClass}' but supplied id was of type '${event.getEntityId().getClass()}'","messagePattern":"Supplied id had wrong type: entity '(.+?)' has id type '(.+?)' but supplied id was of type '(.+?)'","errorType":"exception","errorClass":"TypeMismatchException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java","lineNumber":68,"sourceCode":"\t * @param event The load event to be handled.\n\t */\n\t@Override\n\tpublic void onLoad(@Nonnull LoadEvent event, @Nonnull LoadType loadType) {\n\t\tfinal var persister = getPersister( event );\n\t\tif ( persister == null ) {\n\t\t\tthrow new HibernateException( \"Unable to locate persister: \" + event.getEntityClassName() );\n\t\t}\n\t\tcheckId( event, loadType, persister );\n\t\tdoOnLoad( persister, event, loadType );\n\t}\n\n\tprivate void checkId(@Nonnull LoadEvent event, @Nonnull LoadType loadType, @Nonnull EntityPersister persister) {\n\t\tfinal Object id = event.getEntityId();\n\t\tif ( !persister.getIdentifierMapping().getJavaType().isInstance( id )\n\t\t\t\t&& !( id instanceof DelayedPostInsertIdentifier ) ) {\n\t\t\tfinal Class<?> idClass = persister.getIdentifierType().getReturnedClass();\n\t\t\tif ( handleIdType( persister, event, loadType, idClass ) ) {\n\t\t\t\tthrow new TypeMismatchException(\n\t\t\t\t\t\t\"Supplied id had wrong type: entity '\" + persister.getEntityName()\n\t\t\t\t\t\t\t\t+ \"' has id type '\" + idClass\n\t\t\t\t\t\t\t\t+ \"' but supplied id was of type '\" + event.getEntityId().getClass() + \"'\"\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t@Nullable\n\tprotected EntityPersister getPersister(@Nonnull final LoadEvent event) {\n\t\tfinal Object instanceToLoad = event.getInstanceToLoad();\n\t\tif ( instanceToLoad != null ) {\n\t\t\t//the load() which takes an entity does not pass an entityName\n\t\t\tevent.setEntityClassName( instanceToLoad.getClass().getName() );\n\t\t\treturn event.getSession().getEntityPersister( null, instanceToLoad );\n\t\t}\n\t\telse {\n\t\t\treturn event.getFactory().getMappingMetamodel().getEntityDescriptor( event.getEntityClassName() );","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java#L50-L86","documentation":"Error \"Supplied id had wrong type: entity '${persister.getEntityName()}' has id type '${idClass}' but supplied id was of type '${event.getEntityId().getClass()}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a supplied argument's Java type does not match the type expected by the mapping or parameter definition.","commonSituations":"Typical situations: passing an id of the wrong Java type; binding a filter/query parameter with an incompatible value; generic type erasure hiding a wrong argument type.","solutions":["Pass an identifier whose Java type matches the entity's @Id type (e.g. Long vs Integer).","Check for auto-boxing or deserialization that produced the wrong id wrapper type."],"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"}