{"record":{"id":"e3febb66bffe57c3","repo":"hibernate/hibernate-orm","slug":"s-cannot-be-treated-as-s","errorCode":null,"errorMessage":"`%s` cannot be treated as `%s`","messagePattern":"`(.+?)` cannot be treated as `(.+?)`","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ValueMapping.java","lineNumber":46,"sourceCode":"\t}\n\n\t/**\n\t * Treat operation.  Asks the ValueMapping to treat itself as the\n\t * given `targetType`, if it can.\n\t *\n\t * @apiNote This is not necessarily limited to things the ValueMapping\n\t * itself implements.\n\t *\n\t * @implNote This default implementation is however limited to just\n\t * things the ValueMapping itself implements.\n\t *\n\t */\n\tdefault <X> X treatAs(Class<X> targetType) {\n\t\tif ( targetType.isInstance( this ) ) {\n\t\t\treturn targetType.cast( this );\n\t\t}\n\n\t\tthrow new IllegalArgumentException(\n\t\t\t\tString.format(\n\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\"`%s` cannot be treated as `%s`\",\n\t\t\t\t\t\tgetClass().getName(),\n\t\t\t\t\t\ttargetType.getName()\n\t\t\t\t)\n\t\t);\n\t}\n}\n","sourceCodeStart":28,"sourceCodeEnd":56,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ValueMapping.java#L28-L56","documentation":"Error \"`%s` cannot be treated as `%s`\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a TREAT expression targets a type that the value mapping cannot be narrowed to.","commonSituations":"See trigger scenarios.","solutions":["Use treat() only with a subtype of the path's declared type.","Check the inheritance hierarchy: the treat target must be related to the declared type of the expression."],"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"}