Search code examples
javagoogle-app-enginejdogoogle-cloud-datastoreeventual-consistency

Migrating existing entities to use entity groups


I am working with a legacy GAE system, using JDO 2.3, which does not use entity groups, but I now wish use entity groups, to take advantage of transactions. Having added a one-to-many relationship on two entity types, this works correctly for new entities created, but causes problems when working with existing legacy entities without the parent-child relationship (unable to delete the child entity).

How do I migrate the existing legacy entities to use the new schema? I have tried updating the parent on the child classes but received a org.datanucleus.store.appengine.DatastoreRelationFieldManager$ChildWithoutParentException ... A parent cannot be established or changed once an object has been persisted.


Solution

  • First, you can still use Transactions outside of an entity-group - it's called cross-group transactions (XG transactions). You are limited to 25 entity groups in the transaction though.

    Note: in your case, every entity is an entity group.

    The entity-group of an entity is an immutable property defined at creation time. What this means is that you would need to delete and then write a new entity with the correct parent set, in a transaction of course.