My app id is gusclabs.
Index entry in datastore-index.xml:
<datastore-index kind="ItemGroupOptionalQuantities" ancestor="true" source="manual">
<property name="quantityFrom" direction="asc"/>
</datastore-index>
Error in appspot-log:
Type 'com.google.appengine.api.datastore.DatastoreNeedIndexException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="ItemGroupOptionalQuantities" ancestor="true" source="manual">
<property name="quantityFrom" direction="asc"/>
</datastore-index>
I updated the entities after deploy the app in a new version.
When I use a query using quantityFrom to order, I have this error.
--- start query ----
Query query = new Query("ItemGroupOptionalQuantities");
query.setAncestor(ancestorKey);
query.addSort("quantityFrom", Query.SortDirection.ASCENDING)
PreparedQuery preparedQuery = datastore.prepare(query);
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10);
QueryResultList<Entity> entities = preparedQuery.asQueryResultList(fetchOptions);
--- end query ---
If you just update the app then you will have to wait a few minutes for these indexes to be built. From the dashboard of your app if you visit the Datastore Indexes pages you should be able to see what kind of indexes you have and in what state they are.
Solved.
The right place for the datastore-indexes.xml file is "/war/WEB-INF", not "/war/WEB-INF/appengine-generated"
Thanks Patrick and Lipis.
Related
I'd like to configure LocalDatastoreServiceTestConfig such that queries will fail if a compound index is needed (e.g., a query with a sort on multiple properties). Is there a way to do this?
I tried new LocalDatastoreServiceTestConfig().setNoIndexAutoGen(true) but it had no effect.
(There is a corresponding way to do this with the Python SDK.)
I assume by "fail" you mean "throw an exception" or something similar.
If so, you should set the autoGenerate attribute in your WEB-INF/datastore-indexes.xml to false.
Example WEB-INF/datastore-indexes.xml:
<datastore-indexes autoGenerate="false">
</datastore-indexes>
Setting autoGenerate to false will make a query that requires a composite index throw an exception.
Example code:
try {
Query q = new Query("Action")
.addSort("encrypter", Query.SortDirection.ASCENDING)
.addSort("requester", Query.SortDirection.ASCENDING)
.addSort("time", Query.SortDirection.DESCENDING);
//...snip...
} catch (Exception e) {
log.severe(e.toString());
}
I tested this and got an exception logged as expected:
SEVERE: com.google.appengine.api.datastore.DatastoreNeedIndexException: Query com.google.appengine.api.datastore.dev.LocalCompositeIndexManager$IndexComponentsO
nlyQuery#f9f81ad3 requires a composite index that is not defined. You must update C:\appengine-java-sdk\dev\core1\war\WEB-INF\datastore-indexes.xml or enable au
toGenerate to have it automatically added.
The suggested index for this query is:
<datastore-index kind="Action" ancestor="false" source="manual">
<property name="encrypter" direction="asc"/>
<property name="requester" direction="asc"/>
<property name="time" direction="desc"/>
</datastore-index>
For more information, see datastore-indexes.xml reference.
I´m working with objectify on appengine, I tried to add a cron job to delete all temp entities which are older than an hour:
Iterable<Key<Entry>> allKeys = ofy().load().type(Entry.class)
.filter("temporary", true)
.filter("createdAt", oneHourAgo).keys();
if(allKeys != null){
ofy().delete().keys(allKeys);
}
but i always get an Exception when executing the cron job on the appengine server:
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Entry" ancestor="false" source="manual">
<property name="temporary" direction="asc"/>
<property name="createdAt" direction="asc"/>
</datastore-index>
does anybody know why this happens? The job works if I remove:
.filter("createdAt", oneHourAgo)
When you use your app with a Development server, the development server tries to figure out which indexes you need and places them in the index-definition file automatically. Since you use this query in a cron job, the development server cannot help you here. You will need to add a definition for this index manually.
Java Datastore Index Configuration
I have been trying to use Query.setOrdering(xxxx desc) but AppEngine gives ServerError : Unable to process the request.
Admin Console :
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Chat_messages" ancestor="false" source="manual">
<property name="FROM_TO" direction="asc"/>
<property name="TIME" direction="desc"/>
</datastore-index>
My code in servlet :
Query q=pm.newQuery(Chat_messages.class);
q.setFilter("FROM_TO == email_emailto || FROM_TO == emailto_email");
q.declareParameters("String email_emailto,String emailto_email");
q.setRange(0, 50);
q.setOrdering("TIME desc");
With the Python runtime, the process of running the app locally with the dev server generates the index file.
Are you actually getting an error about not having the correct index? The index that you have put in your datastore-index.xml is a single property index. This means that it is automatically built by Datastore and will not show up in your console.
You can see this page which describes which queries you can perform without needing to upload any indexes.
I encountered the following problem.
I have simple (just started) web application.
I created new Web Application project and generated entity with #ManyToOne (so there are to enitities in fact) class from the database. This is what happens when i try to run it.
First run:
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group WHERE (group_id = 1)' at line 1 Error Code: 1064 Call: SELECT group_id, acc_level, name FROM group WHERE (group_id = ?) bind => [1 parameter bound] Query: ReadObjectQuery(name="file:/D:/Projekty/Sell Your Thing/build/web/WEB-INF/classes/_Sell_Your_ThingPU" referenceClass=Group1 )
Second run: Everything is correct
After making Netbeans to recompile (for example I add a space somewhere) i get this:
com.model.User cannot be cast to com.model.User
After few refreshes of the page i get this:
WEB9031: WebappClassLoader unable to load resource [sun.reflect.ConstructorAccessorImpl], because it has not yet been started, or was already stopped
I am so confused right now:/
(I use glassfish and mysql)
edit:
I resolved the firt error by changing the name from group to user_group because its a keyword.
I also resolved the last error by adding
<property name="openjpa.DynamicEnhancementAgent" value="false"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
in persistance.xml
I still cannot resolve the casting one. I don't understand why i have some class leak or whatever it is while I have really simple code. (generated entities in netbeans)
method causing errors:
public String getUserNameById(int id) {
em = getEntityManager();
Query q = em.createNamedQuery("User.findByUserId");
q.setParameter("userId", id);
User u = (User) q.getSingleResult();
em.close();
return u.getName();
}
and i just use it in JSF
<h:outputText value="#{userBean.getUserNameById(2)}" />
The first error is likely caused by the fact that you chose group as the name of your table. group being a reserved SQL keyword, the query is invalid. Choose another name (and don't choose select, order or insert as the name :-))
I am writing a query but it always says "No matching index found". I don't know why. My code is as below:
Query query = pm.newQuery(Classified.class);
query.setFilter("emp_Id == emp");
query.setOrdering("upload_date desc");
query.declareParameters("String emp");
List<Classified> results = (List<Classified>)query.execute(session.getAttribute("emp_Id").toString());
<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
<datastore-index kind="Classified" ancestor="false">
<property name="emp_Id" direction="asc" />
<property name="category" direction="asc" />
<property name="upload_date" direction="desc" />
</datastore-index>
</datastore-indexes>
I have added the above index, but it did not help.
I believe you need to configure a Datastore Index. There's probably one already generated for you in Eclipse at WEB-INF/appengine-generated/datastore-indexes-auto.xml that you just need to copy to WEB-INF/datastore-indexes.xml and deploy again.
Because this needs to be somewhere on the internet...
I kicked myself when I found this out
The error is you do not have a index matching what the query would like to perform. You can have multiple indexes for each entity.
In the Logcat, error, it will tell you exactly what index to set and what order the elements need to be.
ie, if the error says it wants (it wont be nicely formatted):
<datastore-index kind="Classified" ancestor="false">
<property name="category" direction="desc" />
<property name="upload_date" direction="desc" />
</datastore-index>
then Project -> war -> WEB-INF -> appengine-generated -> datastore-indexes-auto.xml and add exactly that. Then, redeploy the project.
Next go into your Google Cloud Console and look at Datastore -> indexes. It should say that the index is being prepared (This goes quicker if you can kill all apps connected and shut down the instance in the console).
Once this has moved into the list of other indexes, rerun the your application and it wont error out with regards to the index anymore.
Go get it Gentlemen/Ladies
The index you define must hold all possible results in the order they will be returned. Your query asks for a particular emp_Id, ordered by upload_date, but your index is ordered primarily by category.
Try removing the category line from your index definition, or swapping the order of category and upload_date, to make upload_date the primary sort order for the index. If another part of your code relies on the category line, you may have to make two separate indices (which incurs some computational cost).
Edit: see comment below by Nick Johnson re. extra parameters.
I am running into this issue at the moment when doing a single property query such as:
const query = datastore
.createQuery('Emailing_dev')
.filter('status', '=', 'Scheduled')
In my case, I should not be getting any errors, however I get Error 9: No matching index found.
If I defined the single property index twice in the yaml, it works:
indexes:
- kind: Emailing_dev
properties:
- name: status
- name: status
but this for sure must be a bug..!!