{"record":{"id":"3f83e52ef6a3bc26","repo":"hibernate/hibernate-orm","slug":"unsupported-duration-unit-unit","errorCode":null,"errorMessage":"unsupported duration unit: {unit}","messagePattern":"unsupported duration unit: (.+?)","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java","lineNumber":253,"sourceCode":"\t\t\tcase MINUTE:\n\t\t\t\tpattern.append(\"minute(10)\");\n\t\t\t\tbreak;\n\t\t\tcase HOUR:\n\t\t\t\tpattern.append(\"hour(8)\");\n\t\t\t\tbreak;\n\t\t\tcase DAY:\n\t\t\tcase WEEK:\n\t\t\t\tpattern.append(\"day(7)\");\n\t\t\t\tbreak;\n\t\t\tcase MONTH:\n\t\t\tcase QUARTER:\n\t\t\t\tpattern.append(\"month(7)\");\n\t\t\t\tbreak;\n\t\t\tcase YEAR:\n\t\t\t\tpattern.append(\"year(7)\");\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new SemanticException(\"unsupported duration unit: \" + unit);\n\t\t}\n\t\tpattern.append(\" as bigint)\");\n\t\tswitch (unit) {\n\t\t\tcase WEEK:\n\t\t\t\tpattern.append(\"/7\");\n\t\t\t\tbreak;\n\t\t\tcase QUARTER:\n\t\t\t\tpattern.append(\"/3\");\n\t\t\t\tbreak;\n\t\t\tcase NATIVE:\n\t\t\tcase NANOSECOND:\n\t\t\t\tpattern.append(\"*1e9\");\n\t\t\t\tbreak;\n\t\t}\n\t\treturn pattern.toString();\n\t}\n\n\t@Override","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java#L235-L271","documentation":"MimerSQLDialect.timestampdiffPattern() builds a 'cast((?3-?2) <unit>(n) as bigint)' expression and only handles NATIVE, NANOSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER and YEAR. Any other TemporalUnit reaches the default branch and throws SemanticException('unsupported duration unit: ...') during query translation.","triggerScenarios":"Calling the HQL timestamp_diff/duration function on Mimer SQL with an uncovered unit, most commonly DAY_OF_MONTH, DAY_OF_WEEK or DAY_OF_YEAR — e.g. 'timestamp_diff(e.t2, e.t1, DAY_OF_MONTH)' — while the sibling extractPattern() happily supports DAY_OF_MONTH/DAY_OF_WEEK/DAY_OF_YEAR, which makes the mismatch easy to hit.","commonSituations":"Reusing a unit enum originally written for extract() in a duration calculation; porting date-diff utilities from H2/PostgreSQL profiles to Mimer; dynamic report builders letting users choose diff units.","solutions":["Use a supported unit (DAY, WEEK, MONTH, QUARTER, YEAR, HOUR, MINUTE, SECOND, NANOSECOND) — DAY_OF_MONTH/DAY_OF_WEEK/DAY_OF_YEAR are only supported by extract(), not timestamp_diff, on Mimer","Compute the difference in Java with ChronoUnit.between and filter in memory or bind the result","Subclass MimerSQLDialect and override timestampdiffPattern() to map the extra units (e.g. DAY_OF_MONTH to day(7))"],"exampleFix":"// before - extract supports DAY_OF_MONTH on Mimer, timestamp_diff does not\n\"select timestamp_diff(e.endTs, e.startTs, DAY_OF_MONTH) from Session e\"\n\n// after\n\"select timestamp_diff(e.endTs, e.startTs, DAY) from Session e\"","handlingStrategy":"validation","validationCode":"private static final Set<TemporalUnit> MIMER_DIFF_UNITS = EnumSet.of(\n        TemporalUnit.NATIVE, TemporalUnit.NANOSECOND, TemporalUnit.SECOND, TemporalUnit.MINUTE,\n        TemporalUnit.HOUR, TemporalUnit.DAY, TemporalUnit.WEEK, TemporalUnit.MONTH,\n        TemporalUnit.QUARTER, TemporalUnit.YEAR);\n\nstatic TemporalUnit mimerSafeDiffUnit(TemporalUnit unit) {\n    // note: DAY_OF_MONTH/DAY_OF_WEEK/DAY_OF_YEAR work with extract() but NOT timestamp_diff on Mimer\n    return MIMER_DIFF_UNITS.contains(unit) ? unit : TemporalUnit.DAY;\n}","typeGuard":"static boolean isMimerDiffUnit(TemporalUnit u) {\n    return u == TemporalUnit.YEAR || u == TemporalUnit.QUARTER || u == TemporalUnit.MONTH\n        || u == TemporalUnit.WEEK || u == TemporalUnit.DAY || u == TemporalUnit.HOUR\n        || u == TemporalUnit.MINUTE || u == TemporalUnit.SECOND\n        || u == TemporalUnit.NANOSECOND || u == TemporalUnit.NATIVE;\n}","tryCatchPattern":"try {\n    return session.createQuery(hql).getResultList();\n} catch (SemanticException e) {\n    if ( String.valueOf(e.getMessage()).startsWith(\"unsupported duration unit\") ) {\n        // downgrade the unit to DAY or compute in Java\n    }\n    throw e;\n}","preventionTips":["Remember extract() and timestamp_diff support different unit sets on Mimer - validate them separately","Map user-facing unit options to a per-dialect whitelist before query construction","Cover datetime units in dialect-specific integration tests"],"tags":["hibernate","mimer-sql","temporal-unit","timestampdiff","duration"],"backgroundTag":"temporal-unit-not-supported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}