Can someone tell me how to get Text value from Google App Engine datastore using Java? I have some objects in a data store with a Text attribute named longDescription. When I try this:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Query q = new Query("Items"); PreparedQuery pq = ds.prepare(q); for (Entity result : pq.asIterable()) { Text longDescription = (Text)result.getProperty("longDescription"); }
I get this warning in the longDescription target line:
WARNING: /pstest java.lang.ClassCastException: java.lang.String cannot be cast to com.google.appengine.api.datastore.Text
Here I am absolutely without hesitation. The only line in my code is the literal "longDescription", which is used to retrieve the correct property. If I put this just above the destination line:
log.warning("Type is " + (result.getProperty("longDescription")).getClass());
I see the following output:
WARNING: Type is class com.google.appengine.api.datastore.Text
Ok, so result.getProperty ("longDescription") really, really is a Text object that is passed as an object. I even tried using the full name (com.google.appengine.api.datastore.Text), and not just the text with the same results. Where does the cast of the string go? And more importantly, how do I get this text from the data store? I am here and any help would be appreciated!
Oh, another relevant note: This is the purpose I used when pasting the property into the data store:
Entity eItem = new Entity("Items"); eItem.setProperty("longDescription", new Text(req.getParameter("ldes"))); ds.put(eItem);
When I look at the description in my management console, it seems to be over 500 characters, and it looks like this:
<Text: This is a long form description of an item in the store that is access...>
Did I screw something when I inserted it? If so, how do you insert text elements into the data warehouse?