Field Migration in JDO

We use JDO in one of our projects. This works for quite some time, and naturally we need to change the model a bit.

What is the best practice when moving fields in entity classes in JDO?

enum MyEnum { REGULAR, MYOLDTYPE // Delete this } @PersistenceCapable public class Entity { @Persistent MyEnum myEnumType; @Persistent String myString; // Rename this } 

If I delete the enumeration value, there will be an exception if it is already saved when loading from the database, how to transfer this?

If I would like to rename myString to myNewString, how to rename a column to a new name?

+6
source share
1 answer

First, look at your data warehouse (RDBMS ?, something else?) To find out if you are stored as String or numeric.

If you change Enum, then you are responsible for

  • Migrating data warehouse content

  • Change the definition of Enum so that Enum.valueOf (String) returns what you want to bind the old value to. Alternatively, if they are stored in an RDBMS, use the DataNucleus extension at the foot of http://www.datanucleus.org/products/accessplatform_3_0/jdo/types.html , where you define the method for obtaining Enum for the string value.

+1
source

Source: https://habr.com/ru/post/888034/


All Articles