views:

351

answers:

1

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?

A: 
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.

Thilo
When I try that I get the following error:"java.lang.String cannot be cast to com.google.appengine.api.datastore.Text"
Lloyd
"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.
Thilo
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.
Lloyd
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.
Thilo