{"record":{"id":"9b7322dd359579a2","repo":"hibernate/hibernate-orm","slug":"unrecognized-field-unit","errorCode":null,"errorMessage":"unrecognized field: \" + unit","messagePattern":"unrecognized field: \" \\+ unit","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java","lineNumber":944,"sourceCode":"\t\t\t\t\tcase DAY:\n\t\t\t\t\t\treturn \"extract(day from ?3-?2)\";\n\t\t\t\t\t//in order to avoid multiple calls to extract(),\n\t\t\t\t\t//we use extract(epoch from x - y) * factor for\n\t\t\t\t\t//all the following units:\n\n\t\t\t\t\t// Note that CockroachDB also has an extract_duration function which returns an int,\n\t\t\t\t\t// but we don't use that here because it is deprecated since v20.\n\t\t\t\t\t// We need to use round() instead of cast(... as int) because extract epoch returns\n\t\t\t\t\t// float8 which can cause loss-of-precision in some cases\n\t\t\t\t\t// https://github.com/cockroachdb/cockroach/issues/72523\n\t\t\t\t\tcase HOUR:\n\t\t\t\t\tcase MINUTE:\n\t\t\t\t\tcase SECOND:\n\t\t\t\t\tcase NANOSECOND:\n\t\t\t\t\tcase NATIVE:\n\t\t\t\t\t\treturn \"round(extract(epoch from ?3-?2)\" + EPOCH.conversionFactor( unit, this ) + \")::int\";\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new SemanticException( \"unrecognized field: \" + unit );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tswitch (unit) {\n\t\t\t\t\tcase YEAR:\n\t\t\t\t\t\treturn \"extract(year from ?3-?2)\";\n\t\t\t\t\tcase QUARTER:\n\t\t\t\t\t\treturn \"(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)\";\n\t\t\t\t\tcase MONTH:\n\t\t\t\t\t\treturn \"(extract(year from ?3-?2)*12+extract(month from ?3-?2))\";\n\t\t\t\t\t// Prior to v20, Cockroach didn't support extracting from an interval/duration,\n\t\t\t\t\t// so we use the extract_duration function\n\t\t\t\t\tcase WEEK:\n\t\t\t\t\t\treturn \"extract_duration(hour from ?3-?2)/168\";\n\t\t\t\t\tcase DAY:\n\t\t\t\t\t\treturn \"extract_duration(hour from ?3-?2)/24\";\n\t\t\t\t\tcase NANOSECOND:\n\t\t\t\t\t\treturn \"extract_duration(microsecond from ?3-?2)*1e3\";","sourceCodeStart":926,"sourceCodeEnd":962,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java#L926-L962","documentation":"EmbeddableFunctionTableReference is the from-element for an embeddable backed by a table-valued SQL function; its only 'table' is the function's table expression. resolveTableReference returns itself for that one expression and throws UnknownTableReferenceException for any other name - meaning translation asked a function-backed embeddable for a named table it cannot possibly provide.","triggerScenarios":"SQL AST resolution requesting a table expression different from the function's tableExpression on an embeddable mapped to a table-valued function - typically when custom dialect/function table references are mixed with named-table resolution, or when a path into the embeddable is resolved with a secondary/subclass table name.","commonSituations":"Custom table-valued-function mappings (@TableFunctionTable? / function table references) after refactors that changed table expressions; dialect extension code; Hibernate version changes in how embeddable function tables expose names.","solutions":["Ensure every selectable of the function-backed embeddable resolves through the function reference itself - pass its own tableExpression, not a base-table name.","Align the mapping so paths into that embeddable never need secondary/subclass tables.","Fix custom dialect/function table reference implementations to keep a single consistent table expression.","Upgrade Hibernate; report with the function mapping if core code requested the wrong expression."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return query.getResultList();\n} catch ( UnknownTableReferenceException e ) {\n    // log the requested table expression vs the function reference's own tableExpression\n    LOG.warn(\"Function-table mismatch: {}\", e.getMessage());\n    throw e; // needs mapping/code fix, not a runtime retry\n}","preventionTips":["Keep exactly one table expression for function-backed embeddables and resolve all their selectables through it.","In custom dialect function-table code, never mix named base tables into paths rooted at a function reference.","Add a unit test asserting resolveTableReference(fnTableExpression) succeeds and foreign names fail loudly during development, not in production."],"tags":["table-reference","embeddable","table-function","sql-ast","internal"],"backgroundTag":"unknown-table-reference","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}