Skip to content

fix(database): Resolve schema case mismatch in DatabaseDataSet metadata lookup - #928

Merged
jeffjensen merged 1 commit into
mainfrom
656-postgresql-uppercase-schema
Aug 11, 2026
Merged

jeffjensen merged 1 commit into
mainfrom
656-postgresql-uppercase-schema

Conversation

@jeffjensen

@jeffjensen jeffjensen commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes Postgresql with FEATURE_QUALIFIED_TABLE_NAMES and schemas in Uppercase results in NoSuchTableException #656: a multi-schema PostgreSQL FlatXmlDataSet row qualified with a schema name cased differently than the live database (e.g. CORE.USER against a core schema PostgreSQL folded to lower case because it was created unquoted) threw NoSuchTableException, but only on the first access to that schema - a later, differently-cased access to the same schema worked, because it reused metadata cached by the earlier request.
  • Root cause: DatabaseDataSet#initialize() passed the requested schema name straight into IMetadataHandler#getTables(), and DatabaseMetaData#getTables() matches its schema pattern case-sensitively against the live catalog regardless of dbUnit's own FEATURE_CASE_SENSITIVE_TABLE_NAMES setting. A wrongly-cased first request therefore found zero tables - and DatabaseDataSet's own per-schema initialization cache then permanently remembered that schema as already-initialized-but-empty, so even a later, correctly-cased retry kept failing too.
  • Fix: DatabaseDataSet now resolves a requested schema name against DatabaseMetaData#getSchemas()'s actual reported names, case-insensitively, before querying for tables, whenever FEATURE_CASE_SENSITIVE_TABLE_NAMES is off (the default - dbUnit's own case-insensitive-table-names mode). A schema that doesn't exist under any casing still resolves to zero tables exactly as before, so behavior for a genuinely nonexistent schema is unchanged.

Test plan

  • New DatabaseDataSet_MultiSchemaTest case reproduces the mismatch deterministically against H2 (which folds unquoted identifiers to upper case) by requesting a table via its lower-cased schema before any other, correctly-cased access has primed the schema cache - fails with NoSuchTableException before the fix, passes after.
  • New PostgresqlUppercaseSchemaIT confirms the original report's exact scenario against a live PostgreSQL 16 Docker container: a FlatXmlDataSet row qualified with an upper-case schema against a live, unquoted (lower-case) schema, under FEATURE_QUALIFIED_TABLE_NAMES, CLEAN_INSERTs and reads back successfully.
  • Full unit suite green (2059 tests).
  • Full IT suite green against postgresql-16 (358 tests), h2-1-4, hsqldb-2-7, and derby-10-14.

🤖 Generated with Claude Code

https://claude.ai/code/session_017rt6YcFdhBCwafLp6n7mcZ

Summary by Sourcery

Resolve schema case-mismatch issues in DatabaseDataSet metadata lookup so qualified table access works reliably when the database folds schema identifiers to a canonical case.

Bug Fixes:

  • Ensure DatabaseDataSet resolves requested schema names against database-reported schema names before table metadata lookup when case-insensitive table names are configured, preventing NoSuchTableException on first access to differently-cased schemas.

Enhancements:

  • Add a PostgreSQL integration test covering uppercase schema-qualified FlatXmlDataSet rows against a lowercase schema with qualified table names enabled.
  • Extend multi-schema H2 test coverage to verify that a mismatched schema case on first access still locates tables correctly under case-insensitive configuration.

Documentation:

  • Document the schema case-mismatch fix for DatabaseDataSet and issue 656 in the project change log.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed schema-qualified table lookups when schema names use different capitalization from the database.
    • Prevented initial lookups from incorrectly caching an empty schema result and causing later table operations to fail.
    • Improved compatibility with PostgreSQL databases using lowercase schemas and tables.
  • Tests
    • Added regression and integration coverage for case-mismatched schema and table names.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Resolves case-mismatch issues in schema-qualified table lookups by normalizing schema names against database metadata when table-name case sensitivity is disabled, and adds regression coverage and changelog entries for issue #656 across H2 unit tests and PostgreSQL integration tests.

Sequence diagram for schema-qualified table lookup with case-insensitive schema resolution

sequenceDiagram
    participant Client
    participant DatabaseDataSet
    participant Connection
    participant DatabaseMetaData
    participant IMetadataHandler

    Client->>DatabaseDataSet: getTable(schema, tableName)
    activate DatabaseDataSet
    DatabaseDataSet->>DatabaseDataSet: initialize(schema)
    activate DatabaseDataSet

    DatabaseDataSet->>Connection: getConnection()
    activate Connection
    Connection-->>DatabaseDataSet: jdbcConnection
    deactivate Connection

    DatabaseDataSet->>Connection: getMetaData()
    activate Connection
    Connection-->>DatabaseDataSet: databaseMetaData
    deactivate Connection

    DatabaseDataSet->>DatabaseDataSet: resolveActualSchemaName(databaseMetaData, schema)
    activate DatabaseDataSet
    DatabaseDataSet->>DatabaseMetaData: getSchemas()
    activate DatabaseMetaData
    DatabaseMetaData-->>DatabaseDataSet: ResultSet
    deactivate DatabaseMetaData
    DatabaseDataSet-->>DatabaseDataSet: actualSchema (case-insensitive match or original)
    deactivate DatabaseDataSet

    DatabaseDataSet->>IMetadataHandler: getTables(databaseMetaData, actualSchema, tableName, types)
    activate IMetadataHandler
    IMetadataHandler-->>DatabaseDataSet: table metadata
    deactivate IMetadataHandler

    DatabaseDataSet-->>Client: ITable / NoSuchTableException (unchanged semantics for nonexistent schema)
    deactivate DatabaseDataSet
Loading

File-Level Changes

Change Details Files
Normalize requested schema names against database-reported schema casing before metadata lookup when table names are treated case-insensitively.
  • Call a new helper from DatabaseDataSet.initialize() to adjust the schema argument before querying metadata.
  • Introduce resolveActualSchemaName(DatabaseMetaData,String) to scan DatabaseMetaData.getSchemas() and return the actual TABLE_SCHEM value on a case-insensitive match.
  • Short-circuit schema resolution when case-sensitive table names are enabled, schema is null, or no matching schema is found, preserving behavior for non-existent schemas.
  • Ensure ResultSet from getSchemas() is always closed via a finally block to avoid resource leaks.
src/main/java/org/dbunit/database/DatabaseDataSet.java
Add unit and integration tests reproducing issue #656 on H2 and PostgreSQL and verifying correct behavior after the fix.
  • Extend DatabaseDataSet_MultiSchemaTest with a new test that first accesses a table via a differently cased schema and asserts that the table is still found.
  • Create PostgresqlUppercaseSchemaIT integration test that sets up a lowercase schema and table, performs CLEAN_INSERT from a FlatXmlDataSet with an uppercase-qualified tag, and verifies inserted rows via a lowercase-qualified table name.
  • Guard the PostgreSQL IT with an EnabledIfSystemProperty condition on dbunit.profile to run only under the PostgreSQL profile.
  • Manage PostgreSQL schema lifecycle in test setup/teardown, including reconnecting after DDL so the new schema is visible to dbUnit.
src/test/java/org/dbunit/database/DatabaseDataSet_MultiSchemaTest.java
src/test/java/org/dbunit/ext/postgresql/PostgresqlUppercaseSchemaIT.java
Document the fix for issue #656 in the changelog.
  • Add a new entry under the appropriate release in changes.xml describing the original bug, its root cause in DatabaseDataSet initialization and case handling, and the new schema-resolution behavior when FEATURE_CASE_SENSITIVE_TABLE_NAMES is disabled.
src/changes/changes.xml

Assessment against linked issues

Issue Objective Addressed Explanation
#656 Fix the bug where using FEATURE_QUALIFIED_TABLE_NAMES with PostgreSQL and a FlatXmlDataSet containing schema-qualified table names whose schema casing differs from the actual database schema (e.g. CORE.USER vs core) results in NoSuchTableException, especially on first access.
#656 Add regression tests to reproduce and verify the schema-case mismatch behavior with qualified table names (including PostgreSQL-specific coverage).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jeffjensen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ff30de85-7318-4934-8443-59533b363b11

📥 Commits

Reviewing files that changed from the base of the PR and between e23cc75 and ffec4a3.

📒 Files selected for processing (1)
  • src/test/java/org/dbunit/ext/postgresql/PostgresqlUppercaseSchemaIT.java
📝 Walkthrough

Walkthrough

DatabaseDataSet now resolves schema names case-insensitively through JDBC metadata when case-sensitive table names are disabled. Unit and PostgreSQL integration tests cover first-access and uppercase-qualified schema lookups.

Changes

Schema resolution fix

Layer / File(s) Summary
Resolve database-reported schema names
src/main/java/org/dbunit/database/DatabaseDataSet.java, src/changes/changes.xml
DatabaseDataSet resolves requested schemas against JDBC-reported names before querying table metadata. The changelog records issue 656.
Validate mismatched schema access
src/test/java/org/dbunit/database/DatabaseDataSet_MultiSchemaTest.java, src/test/java/org/dbunit/ext/postgresql/PostgresqlUppercaseSchemaIT.java
Tests cover first-access lookups with mismatched casing and PostgreSQL loading with uppercase-qualified names.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant DatabaseDataSet
  participant DatabaseMetaData
  participant PostgreSQL
  Test->>DatabaseDataSet: request schema-qualified table
  DatabaseDataSet->>DatabaseMetaData: getSchemas()
  DatabaseMetaData-->>DatabaseDataSet: lowercase database schema
  DatabaseDataSet->>PostgreSQL: query table metadata using resolved schema
  PostgreSQL-->>DatabaseDataSet: matching table
  DatabaseDataSet-->>Test: return table data
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the schema case-mismatch fix in DatabaseDataSet metadata lookup.
Linked Issues check ✅ Passed The implementation and regression tests address issue #656 by resolving schema casing before metadata lookup.
Out of Scope Changes check ✅ Passed The changelog, implementation, and regression tests are directly related to resolving issue #656.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 656-postgresql-uppercase-schema

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider wrapping the call to resolveActualSchemaName() in DatabaseDataSet.initialize() with existing SQLException-to-DataSetException handling so that callers never see raw SQLExceptions and error reporting stays consistent with the rest of the method.
  • resolveActualSchemaName() scans all schemas on each initialize() call; if this runs frequently on databases with many schemas, you may want to cache a case-insensitive mapping of schema names per connection to avoid repeated full catalog scans.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider wrapping the call to resolveActualSchemaName() in DatabaseDataSet.initialize() with existing SQLException-to-DataSetException handling so that callers never see raw SQLExceptions and error reporting stays consistent with the rest of the method.
- resolveActualSchemaName() scans all schemas on each initialize() call; if this runs frequently on databases with many schemas, you may want to cache a case-insensitive mapping of schema names per connection to avoid repeated full catalog scans.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/test/java/org/dbunit/ext/postgresql/PostgresqlUppercaseSchemaIT.java`:
- Around line 90-94: Update the AssertJ descriptions in the row-count and
username assertions of PostgresqlUppercaseSchemaIT so each .as() message ends
with a period, preserving the existing assertion logic.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 14bbfcf9-199e-4c9b-9445-e833fad52fe2

📥 Commits

Reviewing files that changed from the base of the PR and between 2b6b9af and e23cc75.

📒 Files selected for processing (4)
  • src/changes/changes.xml
  • src/main/java/org/dbunit/database/DatabaseDataSet.java
  • src/test/java/org/dbunit/database/DatabaseDataSet_MultiSchemaTest.java
  • src/test/java/org/dbunit/ext/postgresql/PostgresqlUppercaseSchemaIT.java

Comment thread src/test/java/org/dbunit/ext/postgresql/PostgresqlUppercaseSchemaIT.java Outdated
…ta lookup

DatabaseDataSet#initialize() passed a schema-qualified table's schema
name straight into IMetadataHandler#getTables(), whose underlying
DatabaseMetaData#getTables() matches the schema pattern case
sensitively against the live catalog regardless of dbUnit's own
FEATURE_CASE_SENSITIVE_TABLE_NAMES setting. A database that folds
unquoted identifiers to a canonical case at creation time (e.g.
PostgreSQL folds them to lower case) then found zero tables on the
first request for a differently-cased schema, and DatabaseDataSet's
own per-schema initialization cache permanently remembered that
schema as already-initialized-but-empty, so even a later,
correctly-cased retry kept failing too.

Add DatabaseDataSet#resolveActualSchemaName(), which resolves a
requested schema name against DatabaseMetaData#getSchemas()'s actual
reported names, case-insensitively, before querying for tables,
whenever FEATURE_CASE_SENSITIVE_TABLE_NAMES is off (the default).

* Add a DatabaseDataSet_MultiSchemaTest case reproducing the mismatch
  against H2 (which folds unquoted identifiers upper case) by
  requesting a table via its lower-cased schema before any other,
  correctly-cased access has primed the schema cache.
* Add PostgresqlUppercaseSchemaIT, confirming the original report's
  exact scenario against a live PostgreSQL 16 container: a
  FlatXmlDataSet row qualified with an upper-case schema against a
  live, unquoted (lower-case) schema, under
  FEATURE_QUALIFIED_TABLE_NAMES.

Refs: 656

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rt6YcFdhBCwafLp6n7mcZ
@jeffjensen
jeffjensen force-pushed the 656-postgresql-uppercase-schema branch from e23cc75 to ffec4a3 Compare August 11, 2026 00:04
@jeffjensen

Copy link
Copy Markdown
Member Author

Re: Sourcery's two suggestions - both already hold true in the code as written, no change needed:

  1. SQLException handling - resolveActualSchemaName()'s call site (DatabaseDataSet.java, inside initialize()) is already inside the existing try { ... } catch (SQLException e) { throw new DataSetException(e); } block that wraps the rest of the method (see initialize() lines 236-306). A SQLException from databaseMetaData.getSchemas() is caught and wrapped exactly like every other JDBC call in this method - it was never raw.

  2. Repeated catalog scans - resolveActualSchemaName() is only reached when initialize() doesn't return early, and initialize()'s existing early-return (if (_tableMap != null && _schemaSet.contains(schema)) return;) already caches "have I initialized this schema" per distinct (case-normalized) schema value for the lifetime of the DatabaseDataSet. So the getSchemas() scan runs at most once per distinct schema ever requested, not once per initialize()/table access - the same bound the rest of the method's live-metadata work already relies on.

@jeffjensen
jeffjensen merged commit 8c894e7 into main Aug 11, 2026
29 checks passed
@jeffjensen
jeffjensen deleted the 656-postgresql-uppercase-schema branch August 11, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postgresql with FEATURE_QUALIFIED_TABLE_NAMES and schemas in Uppercase results in NoSuchTableException

1 participant