{"record":{"id":"7aeee49714579bed","repo":"hibernate/hibernate-orm","slug":"cached-version-was-not-of-type-type-getname","errorCode":null,"errorMessage":"Cached version was not of type {type.getName()}","messagePattern":"Cached version was not of type (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/ComparatorUtil.java","lineNumber":24,"sourceCode":"\nimport jakarta.annotation.Nonnull;\nimport org.hibernate.type.BasicType;\n\nimport java.util.Comparator;\n\nclass ComparatorUtil {\n\t@Nonnull\n\tstatic <T> Comparator<Object> versionComparator(BasicType<T> type) {\n\t\treturn (u, v) -> {\n\t\t\tfinal var descriptor = type.getJavaTypeDescriptor();\n\t\t\tfinal T x;\n\t\t\tfinal T y;\n\t\t\ttry {\n\t\t\t\tx = descriptor.cast( u );\n\t\t\t\ty = descriptor.cast( v );\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new IllegalArgumentException( \"Cached version was not of type \" + type.getName(), e );\n\t\t\t}\n\t\t\treturn descriptor.getComparator().compare( x, y );\n\t\t};\n\t}\n}\n","sourceCodeStart":6,"sourceCodeEnd":30,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/ComparatorUtil.java#L6-L30","documentation":"Error \"Cached version was not of type {type.getName()}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Second-level caching is misconfigured or a cache region/key does not match what Hibernate expects.","commonSituations":"Enabling @Cacheable entities without setting hibernate.cache.region.factory_class, custom RegionFactory implementations, or unwrapping Cache to provider types.","solutions":["Use a consistent version property type (@Version Long/Integer/Timestamp) for the cached entity; mixed versions break cache entry comparison."],"exampleFix":"Use a consistent version property type (@Version Long/Integer/Timestamp) for the cached entity; mixed versions break cache entry comparison.","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"}