Quick revision
The short answer
I would choose one abstraction level for most data access, JPA or jOOQ, and isolate the few hot or special queries in a dialect-specific module with one implementation per engine. Migrations hold per-database scripts only where needed, through Flyway vendor folders or Liquibase dbms attributes. Every build runs against all three engines with Testcontainers (Oracle Free and SQL Server images), at least nightly. We avoid or wrap the features that differ sharply, such as empty strings, booleans and identity behaviour, and we measure what each engine costs so we can revisit whether all three are worth supporting.
What to remember
In this answer, we designed a product for three engines by putting most data access in one portable layer, JPA or jOOQ, and isolating the few special queries in a dialect module with one implementation per engine. Migrations share common scripts and add per-vendor folders through Flyway's {vendor} placeholder or Liquibase's dbms attribute. Every build is tested against real engines with Testcontainers, at least nightly for the full matrix. We avoid or wrap the sharp differences such as empty strings, booleans and identity behaviour, and we measure each engine's cost so the decision to support it stays deliberate.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would choose one abstraction level for most data access, JPA or jOOQ, and isolate the few hot or special queries in a dialect-specific module with one implementation per engine. Migrations hold per-database scripts only where needed, through Flyway vendor folders or Liquibase dbms attributes. Every build runs against all three engines with Testcontainers (Oracle Free and SQL Server images), at least nightly. We avoid or wrap the features that differ sharply, such as empty strings, booleans and identity behaviour, and we measure what each engine costs so we can revisit whether all three are worth supporting.
Why this question is asked
On-premise enterprise customers often decide the database, not us, so a product may have to run on PostgreSQL, Oracle and SQL Server at once. Done carelessly, every feature takes three times as long, bugs appear on one engine only, and developers stop trusting the tests. Interviewers ask this design question to see whether we can contain the differences in a few known places. In this answer, we will design the data access layers, the migration layout and the test strategy, list the features to avoid or wrap, and end with how to keep the cost visible.
1Choosing One Abstraction Level
The first decision is how far from SQL most code sits. JPA with Hibernate hides most dialect differences: it generates pagination, identity and type handling per engine, and works well for ordinary entity CRUD. jOOQ keeps us closer to SQL with a type-safe builder and renders each query in the right dialect, which suits products with many reporting or complex queries; note that jOOQ's support for commercial databases such as Oracle and SQL Server requires its commercial editions. Either can work. What matters is that the team picks one as the default, so most code is written once.
A few queries will never be portable: a hot search query that needs PostgreSQL's GIN index, an Oracle hierarchical query with CONNECT BY, or a SQL Server MERGE tuned for one workload. Those go into a dialect-specific module behind an interface, with one implementation per engine, selected at startup.
- Services and domainno SQL, no dialect knowledge
- Portable data accessJPA or jOOQ, about 95 percent of queries
- Dialect modulea few hot or special queries, one class per engine
- Migrationsshared scripts plus vendor folders
- PostgreSQL / Oracle / SQL Server
5 layers, from the top down. Step through them one at a time.
2Migrations With Per-Database Scripts Only Where Needed
Schema changes must also run on three engines. Most DDL can be shared if we stick to common types, but some cannot: identity syntax, index types, partial indexes, data types like TEXT versus CLOB versus NVARCHAR(MAX). Flyway supports a {vendor} placeholder in its locations, which Spring Boot resolves to the database in use, so we keep a common folder plus one folder per engine. Liquibase does the same with a dbms attribute on each changeset.
The version numbers must stay aligned across folders, so V13 exists for every engine even if one of them is empty of real changes. A review rule that every vendor-specific migration comes with its siblings in the same pull request keeps the folders from drifting.
3Testing Every Build Against All Three Engines
Dialect bugs are only found by running on the real engine. An in-memory database such as H2 in compatibility mode does not catch them; it has its own behaviour. Testcontainers starts real databases in Docker for the test run: PostgreSQL, the Oracle Database Free image and the SQL Server image, which requires accepting Microsoft's licence terms in the container configuration.
Oracle and SQL Server containers start slowly and use a lot of memory, so many teams run the primary engine on every pull request and the full matrix nightly and before release. That is the minimum; if bugs keep reaching production on one engine, the matrix moves into every pull request for the data access modules. Check the current image names and container class packages for your Testcontainers version.
4Avoiding or Wrapping the Sharp Differences
Some differences are cheaper to avoid than to handle. Oracle stores empty strings as NULL, so we treat missing text as null everywhere. Boolean columns differ: PostgreSQL has boolean, SQL Server has bit, and Oracle only gained BOOLEAN in 23ai, so older Oracle schemas use NUMBER(1); JPA maps all of these if we let it, but native SQL must not compare with TRUE. Identity behaviour differs, so we use sequences where possible, which all three support. Case sensitivity differs: SQL Server's usual collation compares strings case-insensitively, the others do not, so we normalise values that must compare equal. And identifiers are folded differently, so we never quote mixed-case table names.
| Difference | Rule |
|---|---|
| Empty string is NULL in Oracle | Represent missing text as null everywhere |
| Boolean types differ | Let JPA map them; no TRUE literals in native SQL |
| Identity and sequences | Use sequences with a shared allocationSize |
| Case-insensitive collation on SQL Server | Normalise values that must compare equal |
| Identifier case folding | Unquoted names, one case |
| Pagination syntax | Let JPA or jOOQ generate it |
5Measuring the Cost of Each Engine
Supporting an engine has a real, recurring cost, and it should be visible. I would track a few numbers per engine: CI time and infrastructure spent on its tests, bugs found that were specific to it, time spent on its vendor-specific migrations and dialect classes, and features delayed or limited because of it. Put next to the revenue from customers on each engine, these numbers let product leadership make a deliberate decision about whether all three are still worth supporting, rather than discovering the answer through slowing delivery.
6Follow-up questions
Why not just use JPA everywhere and skip the dialect module?
Because a few queries really need engine-specific features to perform, and forcing them through portable JPQL either makes them slow on every engine or leads to native queries scattered through the code base. A small, explicit dialect module keeps those exceptions in one place with tests for each engine.
Is H2 useful at all in this setup?
It can be useful for very fast unit tests of mapping logic, but it should never be the only database tests run against, because it does not behave like Oracle or SQL Server in exactly the places that cause bugs. Real-engine tests in Testcontainers are what we rely on.
How do you handle Oracle's 30 character identifier limit?
Oracle 12.2 and later allow names up to 128 bytes, but older versions limited them to 30. If the product supports older Oracle releases, a naming rule and a test that checks name lengths in the migrations prevent failures on those customers' databases.
7Conclusion
In this answer, we designed a product for three engines by putting most data access in one portable layer, JPA or jOOQ, and isolating the few special queries in a dialect module with one implementation per engine. Migrations share common scripts and add per-vendor folders through Flyway's {vendor} placeholder or Liquibase's dbms attribute. Every build is tested against real engines with Testcontainers, at least nightly for the full matrix. We avoid or wrap the sharp differences such as empty strings, booleans and identity behaviour, and we measure each engine's cost so the decision to support it stays deliberate.
Open with
I would contain the differences in a few known places. First, one default abstraction for data access, JPA with Hibernate for entity work or jOOQ if the product is query-heavy, so about 95 percent of queries are written once and the library generates the right dialect.
Then, if they want more
The few queries that need engine features, like a full-text search, live in a dialect module behind an interface with one implementation per engine, selected at startup. Second, migrations: a common Flyway folder plus vendor folders through the {vendor} placeholder, or Liquibase changesets with a dbms attribute, with matching version numbers and a review rule that vendor scripts come together.
Third, testing against real engines, never H2 alone. Testcontainers runs PostgreSQL, the Oracle Free image and SQL Server; the main engine on every pull request and the full matrix at least nightly and before release.
Fourth, I would ban or wrap the sharp differences: missing text is null because Oracle turns empty strings into NULL, booleans are left to JPA because Oracle only got BOOLEAN in 23ai, sequences instead of identity where possible, and normalised values because SQL Server compares case-insensitively by default.
Finally I would track what each engine costs in CI time, engine-specific bugs and delayed features, so leadership can decide with numbers whether all three are still worth it.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your product must support PostgreSQL, Oracle and SQL Server for on-premise customers....": https://scrivio-interview-library.netlify.app/databases/oracle-and-sql-server/8221bcc6fd/