Home > Software design >  Is switching table for a view safe to do in runtime when using JDBC?
Is switching table for a view safe to do in runtime when using JDBC?

Time:01-13

I have a legacy table with some data in it, and a running application that uses JDBC to execute queries on the table. I am planning to rename the table and make an updatable view with the same name (as the old table) and columns and types that is referring to another table.

What I am trying to find out, since I have a production environment running, if after this change my JDBC clients will start running and executing queries and updates on the view instead of the table without breaking or needing to restart them. In other words is switching table for a compatible view in the database schema a compatible runtime change for running JDBC clients?

I think that there may be a short period when my old table does not exist, and the view still does not while the DDL queries are executing. I am willing to ignore the short blip. I assume that the clients are using some PreparedStatements.

My stack: PosgreSQL 12, java 11 JDBC, hibernate, JPA.

CodePudding user response:

For any production system (read: a computer that a person, other than yourself, is using) it is always wise to plan downtime for a database change. If downtime only lasts a few seconds, good! But make a plan for downtime in case of the unexpected.

Other than that: this should work just fine. Provided names and column structure are identical, switching between a table & view should be transparent to any JDBC client.

  • Related