首页 > 解决方案 > Change DB column type on the fly

问题描述

given a java service which should have ideally no downtime, i want to change a table's columntype from varchar to longtext while keeping the service alive.

the service is using spring --> jpa, hibernate and talks to a mysql db.

the entity has the mapped attribute, lets call it foobar, delcared as String.

so now at the moment it looks like this:

and i want to do a table modify, so it will be like this:

QUESTION:

If i change the mysql column and keep the java service running, will it still be able to read/write to the column or will it throw an error?

标签: javamysqlhibernatejpajdbc

解决方案


理论上我会说“是”,改变应该是透明的。毕竟这两种类型在 JDBC 中都由相同的java.sql.Types.VARCHAR类型表示。

但是——这是理论——而且由于您的应用程序似乎非常关键,我不会盲目相信该理论。

在 DEV 或 TEST 环境中进行简单的测试会给你答案。

只要确保你使用完全相同的:

  • 数据库版本,
  • JPA 版本,
  • 休眠版,
  • JVM版本,
  • 应用版本,
  • 图书馆,
  • 等等

推荐阅读