Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating fields in JDO

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?

like image 456
jontro Avatar asked May 13 '11 13:05

jontro


1 Answers

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

  1. Migrate the content of the datastore

  2. 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.

like image 60
DataNucleus Avatar answered Sep 26 '22 05:09

DataNucleus