{"record":{"id":"4d99c80d44b4e6f7","repo":"hibernate/hibernate-orm","slug":"object-of-type-can-t-be-cast-to-managedentity","errorCode":null,"errorMessage":"Object of type '{}' can't be cast to ManagedEntity","messagePattern":"Object of type '(.+?)' can't be cast to ManagedEntity","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java","lineNumber":305,"sourceCode":"\t\tthrow new ClassCastException( \"Object of type '\" + entity.getClass() + \"' can't be cast to HibernateProxy\" );\n\t}\n\n\t/**\n\t * Cast the object to ManagedEntity\n\t * (using this is highly preferrable over a direct cast)\n\t * @param entity the entity to cast\n\t * @return the same instance after casting\n\t * @throws ClassCastException if it's not of the right type\n\t */\n\tpublic static ManagedEntity asManagedEntity(final Object entity) {\n\t\tObjects.requireNonNull( entity );\n\t\tif ( entity instanceof PrimeAmongSecondarySupertypes t ) {\n\t\t\tfinal ManagedEntity e = t.asManagedEntity();\n\t\t\tif ( e != null ) {\n\t\t\t\treturn e;\n\t\t\t}\n\t\t}\n\t\tthrow new ClassCastException( \"Object of type '\" + entity.getClass() + \"' can't be cast to ManagedEntity\" );\n\t}\n\n\t/**\n\t * Cast the object to CompositeTracker\n\t * (using this is highly preferrable over a direct cast)\n\t * @param entity the entity to cast\n\t * @return the same instance after casting\n\t * @throws ClassCastException if it's not of the right type\n\t */\n\tpublic static CompositeTracker asCompositeTracker(final Object entity) {\n\t\tObjects.requireNonNull( entity );\n\t\tif ( entity instanceof PrimeAmongSecondarySupertypes t ) {\n\t\t\tfinal CompositeTracker e = t.asCompositeTracker();\n\t\t\tif ( e != null ) {\n\t\t\t\treturn e;\n\t\t\t}\n\t\t}\n\t\tthrow new ClassCastException( \"Object of type '\" + entity.getClass() + \"' can't be cast to CompositeTracker\" );","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java#L287-L323","documentation":"Error \"Object of type '{}' can't be cast to ManagedEntity\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java:305 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure bytecode enhancement is enabled so entities implement ManagedEntity","Guard the cast with instanceof ManagedTypeHelper.asManagedEntity instead of a direct cast"],"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"}