{"record":{"id":"ff1098fc6fe1c6e1","repo":"hibernate/hibernate-orm","slug":"unsupported-unit-for-timestampadd","errorCode":null,"errorMessage":"Unsupported unit for TIMESTAMPADD: ","messagePattern":"Unsupported unit for TIMESTAMPADD: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InterSystemsIRISDialect.java","lineNumber":646,"sourceCode":"\t@Override\n\tpublic String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {\n\t\tswitch (unit) {\n\t\t\tcase YEAR:      return \"{fn TIMESTAMPADD(SQL_TSI_YEAR, ?2, ?3)}\";\n\t\t\tcase QUARTER:   return \"{fn TIMESTAMPADD(SQL_TSI_QUARTER, ?2, ?3)}\";\n\t\t\tcase MONTH:     return \"{fn TIMESTAMPADD(SQL_TSI_MONTH, ?2, ?3)}\";\n\t\t\tcase WEEK:      return \"{fn TIMESTAMPADD(SQL_TSI_WEEK, ?2, ?3)}\";\n\t\t\tcase DAY:\n\t\t\tcase DAY_OF_MONTH:\n\t\t\t\treturn \"{fn TIMESTAMPADD(SQL_TSI_DAY, ?2, ?3)}\";\n\t\t\tcase HOUR:      return \"{fn TIMESTAMPADD(SQL_TSI_HOUR, ?2, ?3)}\";\n\t\t\tcase MINUTE:    return \"{fn TIMESTAMPADD(SQL_TSI_MINUTE, ?2, ?3)}\";\n\t\t\tcase SECOND:    return \"dateadd(second, ?2, ?3)\";\n\t\t\tcase NANOSECOND:\n\t\t\t\treturn \"{fn TIMESTAMPADD(SQL_TSI_FRAC_SECOND, (?2)/1000000, ?3)}\";\n\t\t\tcase NATIVE:\n\t\t\t\treturn \"dateadd(microsecond, ?2, ?3)\";\n\t\t\tdefault:\n\t\t\t\tthrow new UnsupportedOperationException( \"Unsupported unit for TIMESTAMPADD: \" + unit );\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"deprecation\")\n\t@Override\n\tpublic String timestampdiffPattern(TemporalUnit unit,\n\t\t\t\t\t\t\t\t\tTemporalType fromTemporalType,\n\t\t\t\t\t\t\t\t\tTemporalType toTemporalType) {\n\t\tif ( unit == null ) {\n\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_SECOND, ?2, ?3)}\";\n\t\t}\n\t\tswitch (unit) {\n\t\t\tcase YEAR:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_YEAR, ?2, ?3)}\";\n\t\t\tcase QUARTER:\n\t\t\t\treturn \"({fn TIMESTAMPDIFF(SQL_TSI_MONTH, ?2, ?3)}/3)\";\n\t\t\tcase MONTH:\n\t\t\t\treturn \"{fn TIMESTAMPDIFF(SQL_TSI_MONTH, ?2, ?3)}\";","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InterSystemsIRISDialect.java#L628-L664","documentation":"InterSystemsIRISDialect.timestampaddPattern() maps TemporalUnits to IRIS {fn TIMESTAMPADD(...)} / dateadd(...) calls. The switch covers YEAR, QUARTER, MONTH, WEEK, DAY/DAY_OF_MONTH, HOUR, MINUTE, SECOND, NANOSECOND and NATIVE; any other TemporalUnit (for example DAY_OF_WEEK or DAY_OF_YEAR) falls into the default branch and throws UnsupportedOperationException.","triggerScenarios":"Calling the HQL/Hibernate datetime function timestamp_add (or building a Duration expression that lowers to TIMESTAMPADD) with a unit outside the supported set on the IRIS dialect, e.g. 'timestamp_add(e.eventDate, 1, DAY_OF_WEEK)' or the equivalent Java Time offset API with TemporalUnit.DAY_OF_WEEK.","commonSituations":"Passing java.time.temporal.ChronoUnit/TemporalUnit values straight from application enums into datetime arithmetic; porting date-math code from dialects with exhaustive unit coverage; dynamic query builders that let users pick any unit.","solutions":["Convert the unit to one IRIS supports before the query: DAY_OF_WEEK/DAY_OF_YEAR -> DAY (compute weekday/year-of-year offsets in Java where semantics differ)","Perform the date arithmetic in Java (e.g. LocalDateTime.plusDays) and bind the result as a parameter","Extend the dialect by subclassing InterSystemsIRISDialect and overriding timestampaddPattern() for the missing units"],"exampleFix":"// before\nsession.createQuery(\n    \"select timestamp_add(e.occurred, 1, DAY_OF_WEEK) from Event e\") // DAY_OF_WEEK unsupported\n    .getResultList();\n\n// after - use DAY, or compute in Java\nsession.createQuery(\n    \"select timestamp_add(e.occurred, 1, DAY) from Event e\").getResultList();\n// or: e.getOccurred().plus(1, ChronoUnit.DAYS)","handlingStrategy":"validation","validationCode":"private static final Set<TemporalUnit> IRIS_TIMESTAMPADD_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\nstatic TemporalUnit irisSafeAddUnit(TemporalUnit unit) {\n    if ( !IRIS_TIMESTAMPADD_UNITS.contains(unit) ) {\n        throw new IllegalArgumentException(\"IRIS does not support timestamp_add with \" + unit);\n    }\n    return unit;\n}","typeGuard":"static boolean isIrisSupportedUnit(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 unit for TIMESTAMPADD\") ) {\n        // re-issue with a supported unit or do the arithmetic in Java\n    }\n    throw e;\n}","preventionTips":["Whitelist temporal units per dialect in a single mapping utility instead of passing ChronoUnit values through","Do date arithmetic in java.time when the unit semantics matter (day-of-week, day-of-year)","Add dialect-aware unit tests for datetime functions when onboarding a community dialect"],"tags":["hibernate","intersystems-iris","temporal-unit","timestampadd","datetime"],"backgroundTag":"temporal-unit-not-supported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}