{"record":{"id":"e5d20fa2ab39fb8c","repo":"hibernate/hibernate-orm","slug":"unsupported-unit-unit","errorCode":null,"errorMessage":"Unsupported unit: \" + unit","messagePattern":"Unsupported unit: \" \\+ unit","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java","lineNumber":703,"sourceCode":"\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn \"(select (days(t2)-days(t1))*24+(midnight_seconds(t2)-midnight_seconds(t1))/3600 \" +\n\t\t\t\t\t\t\"from lateral(values(\" + fromExpression + ',' + toExpression + \")) as temp(t1,t2))\";\n\t\t\t\t}\n\t\t\tcase YEAR:\n\t\t\t\treturn \"(year(\" + toExpression + \")-year(\" + fromExpression + \"))\";\n\t\t\t// the months_between() function results\n\t\t\t// in a non-integral value, so trunc() it\n\t\t\tcase MONTH:\n\t\t\t\treturn \"trunc(months_between(\" + toExpression + ',' + fromExpression + \"))\";\n\t\t\tcase QUARTER:\n\t\t\t\treturn \"trunc(months_between(\" + toExpression + ',' + fromExpression + \")/3)\";\n\t\t\tcase WEEK:\n\t\t\t\treturn \"int((days\" + toExpression + \")-days(\" + fromExpression + \"))/7)\";\n\t\t\tcase DAY:\n\t\t\t\treturn \"(days(\" + toExpression + \")-days(\" + fromExpression + \"))\";\n\t\t\tdefault:\n\t\t\t\tthrow new UnsupportedOperationException( \"Unsupported unit: \" + unit );\n\t\t}\n\t}\n\n\t@Override\n\tpublic String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {\n\t\tfinal StringBuilder pattern = new StringBuilder();\n\t\tfinal String timestampExpression;\n\t\tif ( unit.isDateUnit() ) {\n\t\t\tif ( temporalType == TemporalType.TIME ) {\n\t\t\t\ttimestampExpression = \"timestamp('1970-01-01',?3)\";\n\t\t\t}\n\t\t\telse {\n\t\t\t\ttimestampExpression = \"?3\";\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif ( temporalType == TemporalType.DATE ) {\n\t\t\t\ttimestampExpression = \"cast(?3 as timestamp)\";","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java#L685-L721","documentation":"The model-part-aware resolveTableReference on MappedByTableGroup: identical semantics to the string variant but triggered when the requested ValuedModelPart's table expression cannot be provided by the underlying mapped-by table group. It marks a mismatch between where a part's columns live (owning side / secondary table) and what the inverse-side group can resolve.","triggerScenarios":"Model-part column resolution (fk parts, embedded parts, id parts) during criteria/HQL translation while the current table group is a one-to-one mappedBy group that lacks the owning-side table; subclass or secondary-table parts of the owner resolved through the inverse.","commonSituations":"Polymorphic queries over one-to-one inverses; @OneToOne(mappedBy) with secondary tables or JOINED inheritance on the owner; post-upgrade regressions in inverse-side resolution.","solutions":["Start the query from the owning entity so model parts resolve against its own table group.","Make the frequently-queried direction the owning side of the association.","Add explicit joins for the owning entity where its columns are needed.","Upgrade to the latest Hibernate 7.x and report persistent cases to HHH."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return query.getResultList();\n} catch ( UnknownTableReferenceException e ) {\n    // model-part table not reachable via mapped-by group: join the owning entity explicitly\n    return em.createQuery(withOwnerJoin(hql), type).getResultList();\n}","preventionTips":["Add explicit joins to the owning entity before referencing its columns from the inverse side.","Avoid secondary tables and JOINED inheritance on entities that are frequent mappedBy targets.","Re-run one-to-one inverse-path queries after each Hibernate upgrade; resolution there changes between versions."],"tags":["one-to-one","mapped-by","model-part","table-reference","sql-ast"],"backgroundTag":"unknown-table-reference","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}