简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM