java - 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:
java entity:
String foobar
MySQL column:
varchar(255) foobar
and i want to do a table modify, so it will be like this:
java entity:
String foobar
MySQL column:
longtext foobar
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?
解决方案
理论上我会说“是”,改变应该是透明的。毕竟这两种类型在 JDBC 中都由相同的java.sql.Types.VARCHAR
类型表示。
但是——这是理论——而且由于您的应用程序似乎非常关键,我不会盲目相信该理论。
在 DEV 或 TEST 环境中进行简单的测试会给你答案。
只要确保你使用完全相同的:
- 数据库版本,
- JPA 版本,
- 休眠版,
- JVM版本,
- 应用版本,
- 图书馆,
- 等等
推荐阅读
- asp.net-mvc - 我们可以用 ASP.NET Web API 替换 ASP.NET MVC
- java - 使用动作侦听器在文本字段中将双精度显示为整数
- amazon-web-services - 如何使用 AWS API Gateway 从 URL 中去除参数?
- python - 获取 Python 子进程中终端内执行的命令的进程 ID
- android - 同时动画父视图和子视图
- reactjs - “预期对应的 JSX 结束标记为”
- android - 如何将字符串转换为日期并在android中显示日期格式
- vue.js - Div(包含项目列表)在外部单击时不关闭
- javascript - 在 Vue.js 组件中使用 D3 鼠标事件坐标
- android - 如何调整布局中的水平条形图?