{"record":{"id":"b1a5caa486a00488","repo":"hibernate/hibernate-orm","slug":"unsupported-temporalunit-for-timestampdiff","errorCode":null,"errorMessage":"Unsupported TemporalUnit for TIMESTAMPDIFF: ","messagePattern":"Unsupported TemporalUnit for TIMESTAMPDIFF: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InterSystemsIRISDialect.java","lineNumber":681,"sourceCode":"\t\t\tcase MONTH:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_MONTH, ?2, ?3)}\";\n\t\t\tcase WEEK:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_WEEK, ?2, ?3)}\";\n\t\t\tcase DAY:\n\t\t\tcase DAY_OF_MONTH:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_DAY, ?2, ?3)}\";\n\t\t\tcase HOUR:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_HOUR, ?2, ?3)}\";\n\t\t\tcase MINUTE:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_MINUTE, ?2, ?3)}\";\n\t\t\tcase SECOND:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_SECOND, ?2, ?3)}\";\n\t\t\tcase NANOSECOND:\n\t\t\t\treturn \"({fn TIMESTAMPDIFF(SQL_TSI_FRAC_SECOND, ?2, ?3)}*1000000)\";\n\t\t\tcase NATIVE:\n\t\t\t\treturn \"({fn TIMESTAMPDIFF(SQL_TSI_FRAC_SECOND, ?2, ?3)}*1000)\";\n\t\t\tdefault:\n\t\t\t\tthrow new UnsupportedOperationException( \"Unsupported TemporalUnit for TIMESTAMPDIFF: \" + unit );\n\t\t}\n\t}\n\t@Override\n\tpublic long getFractionalSecondPrecisionInNanos() {\n\t\treturn 1_000L; //default to nanoseconds for now\n\t}\n\n\t@Override\n\tpublic boolean supportsTableCheck() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic LockingClauseStrategy getLockingClauseStrategy(QuerySpec querySpec, LockOptions lockOptions) {\n\t\treturn NON_CLAUSE_STRATEGY;\n\t}\n\n\t@Override","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InterSystemsIRISDialect.java#L663-L699","documentation":"InterSystemsIRISDialect.timestampdiffPattern() translates timestampdiff calls into {fn TIMESTAMPDIFF(SQL_TSI_*, ...)} expressions. It covers YEAR, QUARTER, MONTH, WEEK, DAY/DAY_OF_MONTH, HOUR, MINUTE, SECOND, NANOSECOND, NATIVE (and a null unit meaning SECOND); every other TemporalUnit hits the default branch and throws UnsupportedOperationException('Unsupported TemporalUnit for TIMESTAMPDIFF: ...').","triggerScenarios":"Calling the HQL function timestamp_diff (or a duration-between expression) with a unit not in the switch, e.g. 'timestamp_diff(e.end, e.start, DAY_OF_WEEK)' or the equivalent Duration API with TemporalUnit.DAY_OF_YEAR, on the IRIS dialect.","commonSituations":"Duration/reporting code that derives its unit from user input or a ChronoUnit enum mapping; queries shared across dialects where the core dialects accept more units; upgrading applications that computed weekday differences elsewhere.","solutions":["Map the requested unit onto a supported one before building the query (DAY_OF_WEEK/DAY_OF_YEAR -> DAY; compute week-day semantics in Java)","Compute differences in Java with java.time.temporal.ChronoUnit.between and filter/compare in memory or via a bound parameter","Subclass InterSystemsIRISDialect and override timestampdiffPattern() to supply an IRIS expression for the missing units"],"exampleFix":"// before\n\"select timestamp_diff(e.closedAt, e.openedAt, DAY_OF_YEAR) from Ticket e\"\n\n// after\n\"select timestamp_diff(e.closedAt, e.openedAt, DAY) from Ticket e\"\n// or compute in Java: ChronoUnit.DAYS.between(opened, closed)","handlingStrategy":"validation","validationCode":"private static final Set<TemporalUnit> IRIS_TIMESTAMPDIFF_UNITS = EnumSet.of(\n        TemporalUnit.YEAR, TemporalUnit.QUARTER, TemporalUnit.MONTH, TemporalUnit.WEEK,\n        TemporalUnit.DAY, TemporalUnit.DAY_OF_MONTH, TemporalUnit.HOUR, TemporalUnit.MINUTE,\n        TemporalUnit.SECOND, TemporalUnit.NANOSECOND, TemporalUnit.NATIVE);\n\nif ( !IRIS_TIMESTAMPDIFF_UNITS.contains(unit) ) {\n    throw new IllegalArgumentException(\"IRIS does not support timestamp_diff with \" + unit);\n}","typeGuard":"static boolean isIrisSupportedDiffUnit(TemporalUnit u) {\n    return u == TemporalUnit.YEAR || u == TemporalUnit.QUARTER || u == TemporalUnit.MONTH\n        || u == TemporalUnit.WEEK || u == TemporalUnit.DAY || u == TemporalUnit.DAY_OF_MONTH\n        || u == TemporalUnit.HOUR || u == TemporalUnit.MINUTE || u == TemporalUnit.SECOND\n        || u == TemporalUnit.NANOSECOND || u == TemporalUnit.NATIVE;\n}","tryCatchPattern":"try {\n    return session.createQuery(hql).getResultList();\n} catch (UnsupportedOperationException e) {\n    if ( String.valueOf(e.getMessage()).startsWith(\"Unsupported TemporalUnit for TIMESTAMPDIFF\") ) {\n        // compute with ChronoUnit.between in Java and bind the result\n    }\n    throw e;\n}","preventionTips":["Route user-selected units through a validated whitelist before they reach HQL","Compute week/weekday differences in Java where semantics are dialect-specific","Keep a single utility for temporal units so dialect differences live in one place"],"tags":["hibernate","intersystems-iris","temporal-unit","timestampdiff","datetime"],"backgroundTag":"temporal-unit-not-supported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}