Support SchemaManager.truncate() via MongoDialect.getTruncateTableStatements()

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Mutation
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hibernate ORM exposes SchemaManager.truncate() (via session.getSchemaManager().truncateMappedObjects()) as a public API for clearing all data from mapped tables while preserving the schema. Applications use this for admin data-reset workflows, multi-tenant data cleanup, and integration test harnesses.

      For MongoDB, this operation is semantically equivalent to calling deleteMany({}) on each mapped collection.

      Current Behavior

      MongoDialect does not override getTruncateTableStatements() or getTableCleaner() from the base Dialect class. The default implementation returns SQL strings like 'truncate table <tableName>', which are not valid MQL. When executed, the MongoDB JDBC driver fails to parse them, the exception is caught by Hibernate's schema management layer, a warning is logged, and execution continues. No data is removed and no error is surfaced to the caller.

      Proposed Fix

      Override getTruncateTableStatements(String[] tableNames) in MongoDialect to emit a MongoDB delete command per collection:

      {"delete": "<collectionName>", "deletes": [{"q": {}, "limit": 0}]}

      This matches TRUNCATE semantics (remove all documents, preserve collection structure and indexes) using valid MQL.

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: