Search code examples
javagoogle-app-enginegoogle-cloud-datastorejdo

Forcefully change "Entity key" for object in Datastore


As the title says, I want to forcefully change the ID of a Kind in the datastore is this possible? The kind uses the following for generating the ID automatically:

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String id;

The reason for this? I accidentally removed some items that I wanna restore, I have their IDs and all their properties, but would like, if possible for the ID to also be the same.

I tried just creating new entities and setting the ID:s but it's not possible it seems. I get no error, but the entity won't be saved.

Thank you!


Solution

  • It seems it actually work to manually set the ID of the object.

    The reason it didn't work before was because I tried using a custom made ID (just to see if it worked), which doesn't work. If you're using the exact same ID you had before it will work to create a new entity with that ID.