{"record":{"id":"ad02e9a418bd6b40","repo":"hibernate/hibernate-orm","slug":"illegal-unit-conversion-this-to-unit","errorCode":null,"errorMessage":"Illegal unit conversion \" + this + \" to \" + unit","messagePattern":"Illegal unit conversion \" \\+ this \\+ \" to \" \\+ unit","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/common/TemporalUnit.java","lineNumber":181,"sourceCode":"\t * the smallest unit of fractional seconds, either milliseconds\n\t * or microseconds. We define this value in order to avoid\n\t * repeatedly converting between {@link #NANOSECOND}s and a\n\t * unit that the database understands. On some platforms this\n\t * is also used to avoid numeric overflow.\n\t *\n\t * @see Dialect#getFractionalSecondPrecisionInNanos()\n\t */\n\tNATIVE;\n\n\tpublic String conversionFactor(TemporalUnit unit, Dialect dialect) {\n\n\t\tif ( unit == this ) {\n\t\t\t//same unit, nothing to do\n\t\t\treturn \"\";\n\t\t}\n\n\t\tif ( unit.normalized() != normalized() ) {\n\t\t\tthrow new SemanticException(\"Illegal unit conversion \" + this + \" to \" + unit);\n\t\t}\n\n\t\tlong from = normalizationFactor( dialect );\n\t\tlong to = unit.normalizationFactor( dialect );\n\t\tif ( from == to ) {\n\t\t\t// the units represent the same amount of time\n\t\t\treturn \"\";\n\t\t}\n\t\telse {\n\t\t\t// if from < to, then this unit represents a\n\t\t\t// smaller amount of time than the given unit\n\t\t\t// we are converting to (so we're going to\n\t\t\t// need to use division)\n\t\t\treturn (from < to ? \"/\" : \"*\")\n\t\t\t\t\t+ factorAsString(from < to ? to / from : from / to);\n\t\t}\n\t}\n","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/common/TemporalUnit.java#L163-L199","documentation":"Error \"Illegal unit conversion \" + this + \" to \" + unit\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate API is violated.","commonSituations":"Occurs when application code or configuration does not satisfy the documented contract of the API being called.","solutions":["Convert only between compatible temporal units (e.g. not months to seconds).","Perform the conversion in application code with explicit logic."],"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"}