{"record":{"id":"67351680cfa5c606","repo":"hibernate/hibernate-orm","slug":"object-of-type-can-t-be-cast-to-hibernateprox","errorCode":null,"errorMessage":"Object of type '{}' can't be cast to HibernateProxy","messagePattern":"Object of type '(.+?)' can't be cast to HibernateProxy","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java","lineNumber":287,"sourceCode":"\t\treturn null;\n\t}\n\n\t/**\n\t * Cast the object to HibernateProxy\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 HibernateProxy asHibernateProxy(final Object entity) {\n\t\tObjects.requireNonNull( entity );\n\t\tif ( entity instanceof PrimeAmongSecondarySupertypes t ) {\n\t\t\tfinal HibernateProxy e = t.asHibernateProxy();\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 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\" );","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java#L269-L305","documentation":"Error \"Object of type '{}' can't be cast to HibernateProxy\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java:287 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not cast arbitrary managed objects to HibernateProxy; check instanceof HibernateProxy first","Use Hibernate.unproxy() utilities to obtain the underlying entity safely"],"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"}