Quick revision
The short answer
Most JPA code moves unchanged, but the edges change: the JDBC driver, URL and pool settings, the Hibernate dialect (usually auto-detected), and id generation, where MySQL's AUTO_INCREMENT becomes a PostgreSQL identity column or sequence. Native queries need rewriting where they use backticks, MySQL's LIMIT offset form, MySQL functions or ON DUPLICATE KEY upserts, case sensitivity changes because MySQL's default collations ignore case, and Flyway or Liquibase migrations are rewritten and tested against PostgreSQL with Testcontainers.
What to remember
In this answer, we listed what changes when a Spring Data JPA application moves from MySQL to PostgreSQL: the driver, URL, auto-detected dialect and pool settings, id generation from AUTO_INCREMENT to identity columns or sequences with matching allocation sizes and reset values, native queries with backticks, MySQL paging, functions and upserts, case sensitivity of identifiers and, more importantly, of string comparisons, and Flyway or Liquibase migrations rewritten and tested against PostgreSQL with Testcontainers.
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.
Most JPA code moves unchanged, but the edges change: the JDBC driver, URL and pool settings, the Hibernate dialect (usually auto-detected), and id generation, where MySQL's AUTO_INCREMENT becomes a PostgreSQL identity column or sequence. Native queries need rewriting where they use backticks, MySQL's LIMIT offset form, MySQL functions or ON DUPLICATE KEY upserts, case sensitivity changes because MySQL's default collations ignore case, and Flyway or Liquibase migrations are rewritten and tested against PostgreSQL with Testcontainers.
Why this question is asked
Spring Data JPA hides much of the database behind entities and repositories, so a switch from MySQL to PostgreSQL can look like a one-line change in application.yml. It rarely is. The differences hide in the places where our code talks to the database directly or relies on its default behaviour, and they tend to show up as production bugs rather than compile errors. Interviewers ask this to see whether we know where those places are. In this answer, we will go through the configuration changes, id generation, native queries, case sensitivity, and finally migrations and tests.
1Driver, URL, Dialect and Pool
The first changes are mechanical. We replace the MySQL driver dependency, com.mysql:mysql-connector-j, with org.postgresql:postgresql, and change the JDBC URL. Hibernate 6 and later detects the dialect from the JDBC connection's metadata, so we can usually remove any spring.jpa.database-platform or hibernate.dialect setting rather than change it; if we keep one, it must name PostgreSQLDialect.
Pool settings deserve a second look. PostgreSQL uses one server process per connection, so many idle connections cost more memory than on MySQL, and max_connections on a managed PostgreSQL may be lower than what we had. Pool sizes per instance, times the number of instances, must fit. MySQL-specific connection properties in the URL, such as useSSL or serverTimezone, have no meaning for PostgreSQL and must go; PostgreSQL uses its own, such as sslmode.
2Id Generation: AUTO_INCREMENT Versus Sequences
On MySQL, entities usually use @GeneratedValue(strategy = GenerationType.IDENTITY), backed by an AUTO_INCREMENT column. PostgreSQL supports IDENTITY too, through identity columns (GENERATED ... AS IDENTITY) or the older serial type, so those entities keep working as long as the schema defines the column that way. But PostgreSQL also has sequences, separate objects that hand out numbers, and with GenerationType.SEQUENCE Hibernate can fetch ids in blocks and batch inserts, which IDENTITY prevents because the id is only known after each insert.
Entities using GenerationType.AUTO are the trap. On PostgreSQL, Hibernate 6 maps AUTO to a sequence, by default one per entity named after it with an allocation size of 50, while on MySQL it fell back to a different strategy (check your version). If the schema does not have those sequences, inserts fail; if the sequence's increment does not match the allocation size, ids can collide. And after copying data from MySQL, every sequence or identity must be moved past the highest existing id.
3Native Queries and MySQL-Specific SQL
JPQL and derived repository methods are translated by Hibernate, so they usually work unchanged. Native queries, written with @Query(nativeQuery = true) or through JdbcTemplate, run as written and must be checked one by one. The common differences are identifier quoting, paging syntax, functions and upserts.
| Area | Usually unchanged | Needs checking |
|---|---|---|
| Repositories | derived methods, JPQL | @Query with nativeQuery = true |
| JDBC access | parameter binding | SQL strings in JdbcTemplate |
| Entities | basic mappings | GenerationType.AUTO, column definitions |
| Types | strings, numbers, dates | TINYINT(1) booleans, unsigned, enums |
| Migrations | nothing | every script, rewritten for PostgreSQL |
Notice the upsert: PostgreSQL's ON CONFLICT needs the conflict target, a unique column or constraint, named explicitly. Booleans also differ: MySQL often stores them as TINYINT(1) and native queries compare with 1, while PostgreSQL has a real boolean type and rejects active = 1 with an operator error. A useful habit is to search the code for nativeQuery = true and for JdbcTemplate calls, and list every one before the migration starts.
4Case Sensitivity of Identifiers and Strings
Two kinds of case sensitivity change. For identifiers, PostgreSQL folds unquoted names to lower case, so a table created as "OrderItem" with quotes must always be quoted that way, while orderitem and OrderItem without quotes are the same table. Hibernate's default naming produces lower-case snake_case names, which avoids the problem; trouble comes from hand-written DDL or @Table names with mixed case.
For data, the difference is bigger. MySQL 8's default collation, utf8mb4_0900_ai_ci, is case- and accent-insensitive, so WHERE email = 'Bob@Example.com' finds bob@example.com, and a unique index treats them as duplicates. PostgreSQL compares strings exactly by default. Login by email, duplicate checks and searches may silently start behaving differently. We fix that deliberately, for example by storing a normalised lower-case value, querying with lower() backed by an expression index, or using the citext extension or a case-insensitive ICU collation where the version and features allow.
5Migrations and Tests Against Real PostgreSQL
Flyway or Liquibase scripts written for MySQL contain MySQL DDL: ENGINE=InnoDB, AUTO_INCREMENT, backticks, UNSIGNED, DATETIME and MySQL index syntax. They will not run on PostgreSQL. For a new PostgreSQL database we usually write a fresh baseline migration that creates the current schema in PostgreSQL syntax, rather than translating years of history, and keep the scripts in a separate location such as db/migration/postgresql.
Tests must run against PostgreSQL itself. An in-memory database such as H2 in MySQL mode hid differences before, and would hide them again. Testcontainers starts a real PostgreSQL in Docker for the tests, and since Spring Boot 3.1 the @ServiceConnection annotation wires its URL and credentials automatically. Running the full test suite there, plus native query tests, is how most of the issues above are caught before production.
6Follow-up questions
Do JPQL queries ever break?
Rarely, but it happens when a JPQL query relies on database behaviour, such as case-insensitive comparison or implicit type conversion. The translated SQL is correct; the semantics of comparison differ. Tests against PostgreSQL catch these.
How do you handle MySQL ENUM columns?
Usually as text with a CHECK constraint, or as a PostgreSQL enum type. On the Java side, @Enumerated(EnumType.STRING) works with a text column; a PostgreSQL enum type needs extra mapping, so text with a check is often simpler.
What about date and time types?
MySQL DATETIME has no time zone and maps to PostgreSQL timestamp; MySQL TIMESTAMP is stored in UTC and converted to the session time zone, which is closer to timestamptz. We decide per column and make the JVM and JDBC time zone settings explicit so values do not shift during the move.
7Conclusion
In this answer, we listed what changes when a Spring Data JPA application moves from MySQL to PostgreSQL: the driver, URL, auto-detected dialect and pool settings, id generation from AUTO_INCREMENT to identity columns or sequences with matching allocation sizes and reset values, native queries with backticks, MySQL paging, functions and upserts, case sensitivity of identifiers and, more importantly, of string comparisons, and Flyway or Liquibase migrations rewritten and tested against PostgreSQL with Testcontainers.
Open with
I would expect most entity and JPQL code to move unchanged, and the work to be at the edges. Configuration first: swap the MySQL driver for the PostgreSQL one, change the JDBC URL and drop MySQL-only properties like serverTimezone, remove the explicit dialect because Hibernate 6 detects it, and recheck pool sizes against PostgreSQL's max_connections.
Then, if they want more
Then id generation: IDENTITY works with PostgreSQL identity columns, but AUTO maps to sequences on PostgreSQL, so I would make the strategy explicit, create sequences whose increment matches the allocation size, and set them past the highest copied id.
Then I would list every native query and JdbcTemplate SQL string: backticks become double quotes, LIMIT offset comma count becomes LIMIT and OFFSET, IFNULL and GROUP_CONCAT become COALESCE and string_agg, ON DUPLICATE KEY UPDATE becomes ON CONFLICT with a target, and tinyint booleans become real booleans.
Case sensitivity is the subtle one: MySQL's default collation ignores case, PostgreSQL does not, so email lookups and unique checks need lower() with an index or citext. Finally, I would write a fresh PostgreSQL baseline for Flyway or Liquibase and run all tests on real PostgreSQL with Testcontainers.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6, MySQL 8, Spring Boot 3.1
- 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 "What changes when a Spring Boot application with Spring Data JPA moves from MySQL to...": https://scrivio-interview-library.netlify.app/databases/database-operations/5c187c4768/