{"record":{"id":"ea75cfd85459d083","repo":"hibernate/hibernate-orm","slug":"illegal-precision-resolvedprecision","errorCode":null,"errorMessage":"Illegal precision: \" + resolvedPrecision","messagePattern":"Illegal precision: \" \\+ resolvedPrecision","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClockHelper.java","lineNumber":70,"sourceCode":"\t}\n\n\tpublic static Clock forPrecision(int resolvedPrecision, int maxPrecision) {\n\t\treturn forPrecision( null, resolvedPrecision, maxPrecision );\n\t}\n\n\tpublic static Clock forPrecision(@Nullable Clock baseClock, int resolvedPrecision, int maxPrecision) {\n\t\treturn switch ( Math.min( resolvedPrecision, maxPrecision ) ) {\n\t\t\tcase 0 -> baseClock == null ? TICK_0 : Clock.tick( baseClock, Duration.ofNanos( 1000000000L ) );\n\t\t\tcase 1 -> baseClock == null ? TICK_1 : Clock.tick( baseClock, Duration.ofNanos( 100000000L ) );\n\t\t\tcase 2 -> baseClock == null ? TICK_2 : Clock.tick( baseClock, Duration.ofNanos( 10000000L ) );\n\t\t\tcase 3 -> baseClock == null ? TICK_3 : Clock.tick( baseClock, Duration.ofNanos( 1000000L ) );\n\t\t\tcase 4 -> baseClock == null ? TICK_4 : Clock.tick( baseClock, Duration.ofNanos( 100000L ) );\n\t\t\tcase 5 -> baseClock == null ? TICK_5 : Clock.tick( baseClock, Duration.ofNanos( 10000L ) );\n\t\t\tcase 6 -> baseClock == null ? TICK_6 : Clock.tick( baseClock, Duration.ofNanos( 1000L ) );\n\t\t\tcase 7 -> baseClock == null ? TICK_7 : Clock.tick( baseClock, Duration.ofNanos( 100L ) );\n\t\t\tcase 8 -> baseClock == null ? TICK_8 : Clock.tick( baseClock, Duration.ofNanos( 10L ) );\n\t\t\tcase 9 -> baseClock == null ? TICK_9 : baseClock;\n\t\t\tdefault -> throw new IllegalArgumentException( \"Illegal precision: \" + resolvedPrecision );\n\t\t};\n\t}\n}\n","sourceCodeStart":52,"sourceCodeEnd":74,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClockHelper.java#L52-L74","documentation":"ClockHelper.forPrecision picks the java.time.Clock used by @CurrentTimestamp-style generators for a fractional-second precision; after clamping with Math.min(resolvedPrecision, maxPrecision) the value must be 0-9. A negative resolved precision — an explicitly negative mapping precision, or a dialect getDefaultTimestampPrecision() below zero when precision is unset — falls through to default and throws IllegalArgumentException('Illegal precision: n').","triggerScenarios":"Setting @CurrentTimestamp(precision = -1) or any negative precision; leaving precision null on a dialect (often a custom/older one) whose default timestamp precision returns a negative sentinel like -1.","commonSituations":"Custom or community dialects reporting -1 for 'unknown' default precision; copy-pasting -1 'unknown' constants from SqlTypes into precision; Hibernate upgrades changing how precision is resolved for a database.","solutions":["Set an explicit precision between 0 and 9 on the @CurrentTimestamp/@CreationTimestamp mapping.","Upgrade to a built-in dialect whose getDefaultTimestampPrecision() is valid (0-9).","For a custom dialect, implement getDefaultTimestampPrecision() to return a value in 0-9."],"exampleFix":"// before\n@CurrentTimestamp(source = VM, precision = -1) // or dialect default of -1\nprivate Instant updated; // ClockHelper.forPrecision -> IllegalArgumentException\n\n// after\n@CurrentTimestamp(source = VM, precision = 6)\nprivate Instant updated;","handlingStrategy":"validation","validationCode":"static boolean isLegalPrecision(int p, int max) {\n    return p >= 0 && Math.min(p, max) <= 9;\n}\n// assert before boot: if (configuredPrecision != null && !isLegalPrecision(configuredPrecision, 9)) fail fast with config error","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only set @CurrentTimestamp precision in 0-9; never reuse -1 'unknown' sentinels.","Test custom dialects' getDefaultTimestampPrecision() in the 0-9 range.","Re-validate temporal mappings after Hibernate major upgrades."],"tags":["hibernate","timestamp","precision","clock","dialect"],"backgroundTag":"timestamp-precision-config","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}