Question

When using spring's JdbcTemplate, I am using the row mapper to map results coming back.

The benefit with this is that there are less places where I have to change my code if I change my mysql schema etc.

Are there any other tips on how to minimize changes in code when adding/removing columns in mysql?

Was it helpful?

Solution

If you are retrieving columns by name (SELECT col1, col2, col3) you will be immune to adding and rearranging of columns. Never use SELECT *.

However if you are removing columns, you have no choice. In fact, how was this suppose to work? Previously you fetched e.g. price column and used it in your business layer. Now the column does not exist - how to handle this?

But adding columns is safe, unless new columns are non-nullable. In this case you will have a problem when adding new records, since VALUES statement won't include new columns. Optional columns are fine.

OTHER TIPS

One tip is to not do SELECT *, select on specific columns so in case you add stuff you don't break your code :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top