How to Migrate an Entity with a String ID to a Long ID

25 views
Skip to first unread message

Kiran Subedi

unread,
Jun 1, 2024, 2:10:09 PMJun 1
to objectify-appengine

Hey everyone,

I'm currently facing a challenge while loading entities from Google Cloud Datastore using Objectify. I'm encountering the following error:

com.googlecode.objectify.LoadException: Error loading entity: At path 'key': Don't know how to translate StringValue{valueType=STRING, value=****} to a number

The issue arises because while most primary keys are Long values (e.g., id:5755441703288832), some are in String format (e.g., name:****). Now, I need to convert these String primary keys to Long to resolve the error.

Could someone please guide me on how to achieve this conversion in Google Cloud Datastore using Objectify?

Any help or insights would be greatly appreciated. Thanks a lot!

Kiran Subedi

unread,
Jun 1, 2024, 2:10:09 PMJun 1
to objectify-appengine

Jeff Schnitzer

unread,
Jun 1, 2024, 2:14:03 PMJun 1
to objectify...@googlegroups.com
Yikes this is not a good place to be. IIRC you can specify Object as an @Id field and you'll be able to read both options, though I could be misremembering and I can't check right now.

Worst comes to worst, you can load/save the entities using google's low level API and fix the ids (which is to say, you can create new entities and delete the old - they have different ids so they are different entities).

Jeff

--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/objectify-appengine/8d6d8c70-985f-4d8b-8486-8e716a3efa25n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages