We are using JDO in one of our projects. This has been running for quite a while and naturally we need to change the model a bit.
What is the best practice when migrating 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 an enum value there will be an exception if it's already persisted when loading from the database, how to migrate this?
If I would like to rename myString to myNewString, how to rename the column to the new name?
Firstly look at your datastore (RDBMS?, something else?) to see if you are persisting as String or numeric-based.
If you change the Enum then you're responsible for either
Migrate the content of the datastore
Change the Enum definition so that Enum.valueOf(String) returns what you want the old value mapped to. Alternatively, if persisting to RDBMS, make use of DataNucleus extension at the foot of http://www.datanucleus.org/products/accessplatform_3_0/jdo/types.html where you define a method to get the Enum for a String value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With