3

I have persistent object, with a string property that often is over 500 charachters. Google App Engine says I need to save it as a com.google.appengine.api.datastore.Text.

How do I either convert a String type to a com.google.appengine.api.datastore.Text type so I can use a setMethod() on the property, or otherwise get my long sting data into that persistent value?

2 Answers 2

6
setMethod(new Text(longStringValue));

String value = text.getValue();

If you are trying to update an existing String column to Text, then I am not sure if that is supported. You can try to change the column type from String to Text and see if it still loads (I can imagine that this might work, please let us know if it does). If not, you need to add a new column and have your application merge them appropriately.

Sign up to request clarification or add additional context in comments.

5 Comments

When I try that I get the following error: "java.lang.String cannot be cast to com.google.appengine.api.datastore.Text"
"try that" = change the column to Text? Too bad. In this case you need to make a new column, and keep the old one, and have your entity migrate its data slowly from the old String column to the new Text column.
You are right. The fact that there were entities with the old datatype in there was causing it grief. Creating a new column and slowly moving there was the right solution. Thanks.
What be cool if GAE/J (DataNucleus?) supported conversion between Text and String automatically (as long as the length constraints are met), though. Would make schema migration easier.
Changing the column type should work just fine. The only difference between text and string is whether or not they're indexed.
2

To convert a String type to a com.google.appengine.api.datastore.Text type I used

Text myText = new Text(myString);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.