Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Datastore problem with query on *User* type
    primarykey
    data
    text
    <p>On <a href="https://stackoverflow.com/questions/764337/how-to-fetch-data-by-user-from-google-datastore">this</a> question I solved the problem of querying Google Datastore to retrieve stuff by user (com.google.appengine.api.users.User) like this:</p> <pre><code>User user = userService.getCurrentUser(); String select_query = "select from " + Greeting.class.getName(); Query query = pm.newQuery(select_query); query.setFilter("author == paramAuthor"); query.declareParameters("java.lang.String paramAuthor"); greetings = (List&lt;Greeting&gt;) query.execute(user); </code></pre> <p>The above works fine - but after a bit of messing around I realized this syntax in not very practical as the need to build more complicated queries arises - so I decided to manually build my filters and now I got for example something like the following (where the filter is usually passed in as a string variable but now is built inline for simplicity):</p> <pre><code>User user = userService.getCurrentUser(); String select_query = "select from " + Greeting.class.getName(); Query query = pm.newQuery(select_query); query.setFilter("author == '"+ user.getEmail() +"'"); greetings = (List&lt;Greeting&gt;) query.execute(); </code></pre> <p>Obviously this won't work even if this syntax with <code>field = 'value'</code> is <a href="http://code.google.com/appengine/docs/java/datastore/queriesandindexes.html" rel="nofollow noreferrer">supported by JDOQL</a> and it works fine on other fields (String types and Enums). The other strange thing is that looking at the Data viewer in the app-engine dashboard the 'author' field is stored as type <em>User</em> but the value is 'user@gmail.com', and then again when I set it up as parameter (the case above that works fine) I am declaring the parameter as a String then passing down an instance of User (user) which gets serialized with a simple <code>toString()</code> (I guess).</p> <p>Anyone any idea?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload