一个简单的查找实体(简单实体,没有后代关系)在同一事务中进行更改并保存该实体。
但会导致以下错误。
21:46:47.883 [Test worker] ERROR c.f.r.e.CustomExceptionControllerAdvice - Application exception occurred
com.google.cloud.datastore.DatastoreException: queries inside transactions must have ancestors
at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.translate(HttpDatastoreRpc.java:128)
at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.translate(HttpDatastoreRpc.java:113)
at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.runQuery(HttpDatastoreRpc.java:181)
at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:180)
at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:177)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.datastore.DatastoreImpl.runQuery(DatastoreImpl.java:176)
at com.google.cloud.datastore.QueryResultsImpl.sendRequest(QueryResultsImpl.java:73)
at com.google.cloud.datastore.QueryResultsImpl.<init>(QueryResultsImpl.java:57)
at com.google.cloud.datastore.DatastoreImpl.run(DatastoreImpl.java:170)
at com.google.cloud.datastore.TransactionImpl.run(TransactionImpl.java:96)
at org.springframework.cloud.gcp.data.datastore.core.DatastoreTemplate.queryKeysOrEntities(DatastoreTemplate.java:266)
at org.springframework.cloud.gcp.data.datastore.repository.query.GqlDatastoreQuery.execute(GqlDatastoreQuery.java:145)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:618)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy185.findByHash(Unknown Source)发布于 2020-09-25 13:50:40
在对2个gcp项目进行了相当的测试和比较后,注意到当应用程序连接到数据存储模式数据库实例中具有Cloud Firestore的gcp项目时,相同的代码运行没有任何错误(上面的异常)。
当应用程序连接到本机模式数据库实例中的Firestore的gcp项目时,导致上述错误。
https://cloud.google.com/datastore/docs/firestore-or-datastore
发布于 2020-09-25 17:27:52
数据存储事务仅在来自相同entity group的实体上操作,这些实体是从公共祖先派生的。为了保持此限制,事务中的所有查询必须包括祖先过滤器,该过滤器指定与事务中的其他操作位于同一实体组中的祖先。
在数据存储区模式的Firestore上的官方GCP documentation中:
如果要在事务中使用查询,则必须将数据组织到实体组中,以便您可以指定与正确数据匹配的祖先筛选器。
请查看StackOverflow上描述可能的解决方法的this帖子。
https://stackoverflow.com/questions/64058423
复制相似问题