{"record":{"id":"529b059ab3dafb06","repo":"hibernate/hibernate-orm","slug":"entity-entityname-is-not-audited","errorCode":null,"errorMessage":"Entity '<entityName>' is not audited","messagePattern":"Entity '<entityName>' is not audited","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/audit/internal/AuditColumnFunction.java","lineNumber":172,"sourceCode":"\t\t\t\t\t\t\tgetArgumentsValidator(),\n\t\t\t\t\t\t\tgetReturnTypeResolver(),\n\t\t\t\t\t\t\tnodeBuilder(),\n\t\t\t\t\t\t\tgetFunctionName()\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t@Override\n\t\tpublic Expression convertToSqlAst(SqmToSqlAstConverter walker) {\n\t\t\tfinal var entityPath = (SqmPath<?>) getArguments().get( 0 );\n\n\t\t\tfinal var tableGroup = walker.getFromClauseAccess()\n\t\t\t\t\t.findTableGroup( entityPath.getNavigablePath() );\n\n\t\t\tfinal var entityMapping = (EntityMappingType) tableGroup.getModelPart();\n\t\t\tfinal var auditMapping = entityMapping.getAuditMapping();\n\t\t\tif ( auditMapping == null ) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Entity '\" + entityMapping.getEntityName()\n\t\t\t\t\t\t\t\t+ \"' is not audited\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// modificationType lives on the root (identifier) table, not subclass tables\n\t\t\tfinal String originalTable = changesetId\n\t\t\t\t\t? entityMapping.getMappedTableDetails().getTableName()\n\t\t\t\t\t: entityMapping.getIdentifierTableDetails().getTableName();\n\t\t\tfinal SelectableMapping selectableMapping = changesetId\n\t\t\t\t\t? auditMapping.getChangesetIdMapping( originalTable )\n\t\t\t\t\t: auditMapping.getModificationTypeMapping( originalTable );\n\n\t\t\tfinal var tableReference = tableGroup.resolveTableReference(\n\t\t\t\t\tentityPath.getNavigablePath(),\n\t\t\t\t\toriginalTable\n\t\t\t);\n","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/audit/internal/AuditColumnFunction.java#L154-L190","documentation":"The HQL audit functions modificationType(path) and changesetId(path) must be applied to an audited entity: AuditColumnFunction.convertToSqlAst resolves the path's EntityMappingType and looks up its AuditMapping to find the modification-type / changeset-id column on the root table. If the entity has no audit mapping, there is nothing to select from, so IllegalArgumentException('Entity ... is not audited') is thrown during query translation to SQL AST.","triggerScenarios":"Writing HQL like 'select modificationType(e) from NotAuditedEntity e', or passing an association path that resolves to a non-audited target entity, in a session where the SQM function is converted to SQL.","commonSituations":"Querying an entity forgotten in the audit configuration; entities intentionally excluded from auditing; copy-pasting a working audit query onto a new entity class.","solutions":["Annotate the entity with Hibernate's auditing annotation (@Audited) so an audit mapping exists.","If the entity is intentionally unaudited, drop the modificationType()/changesetId() function from that query.","Check the path expression - the function applies to the audited root path, not to an unaudited joined association."],"exampleFix":"// before\nList<Object> rows = session\n    .createQuery(\"select modificationType(e) from Document e\", Object.class)\n    .getResultList(); // Document not audited\n// after\n@Audited\n@Entity\npublic class Document { ... } // or query an audited entity instead","handlingStrategy":"validation","validationCode":"// verify the entity is audited before using audit HQL functions\nboolean audited = sessionFactory.getMappingMetamodel()\n    .getEntityDescriptor(Document.class)\n    .getAuditMapping() != null;\nif (!audited) throw new IllegalArgumentException(\"Document is not audited\");","typeGuard":null,"tryCatchPattern":"try {\n    results = session.createQuery(\"select modificationType(e) from Document e\", Object.class).getResultList();\n}\ncatch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().endsWith(\"is not audited\")) {\n        // drop the audit function or annotate the entity @Audited\n    }\n    else throw e;\n}","preventionTips":["Apply the audit functions only to entities you have annotated @Audited","Keep a list of audited entity names and validate queries against it in tests"],"tags":["hibernate","audit","hql","entity-mapping"],"backgroundTag":"entity-not-audited","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}