gpt4 book ai didi

java - 如何通过子对象唯一值或值集访问 Gemfire 对象

转载 作者:行者123 更新时间:2023-12-01 11:55:24 25 4
gpt4 key购买 nike

我的查询看起来像这样,但没有按预期工作。我尝试了很多不同的变体,但我在查询中遗漏了一些东西。

存储库代码:

@Query("SELECT c FROM /customer c, c.emailAddresses email WHERE email.emailAddress = $1")
List<CustomerEntity> findByEmailAddress(String emailAddress);

型号:

public class CustomerEntity {
@Id
protected String id;
private List<CustomerEmailAddressEntity> emailAddresses;
}

public class CustomerEmailAddressEntity {
private Long id;
private String emailAddress;
}

我得到的堆栈如下所示:

Caused by: java.lang.ClassCastException: com.gemstone.gemfire.cache.query.internal.Undefined cannot be cast to com.gemstone.gemfire.cache.query.SelectResults
at com.gemstone.gemfire.internal.cache.PRQueryProcessor.executeSequentially(PRQueryProcessor.java:330)
at com.gemstone.gemfire.internal.cache.PRQueryProcessor.executeQuery(PRQueryProcessor.java:127)
at com.gemstone.gemfire.internal.cache.PartitionedRegionQueryEvaluator.executeQueryOnLocalNode(PartitionedRegionQueryEvaluator.java:1370)
at com.gemstone.gemfire.internal.cache.PartitionedRegionQueryEvaluator.executeQueryOnRemoteAndLocalNodes(PartitionedRegionQueryEvaluator.java:339)
at com.gemstone.gemfire.internal.cache.PartitionedRegionQueryEvaluator.queryBuckets(PartitionedRegionQueryEvaluator.java:442)
at com.gemstone.gemfire.internal.cache.PartitionedRegion.doExecuteQuery(PartitionedRegion.java:1909)
at com.gemstone.gemfire.internal.cache.PartitionedRegion.executeQuery(PartitionedRegion.java:1829)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:234)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:195)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.processQueryUsingParams(BaseCommand.java:1402)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.processQuery(BaseCommand.java:1347)
at com.gemstone.gemfire.internal.cache.tier.sockets.command.Query.cmdExecute(Query.java:88)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:174)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doNormalMsg(ServerConnection.java:809)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doOneMessage(ServerConnection.java:940)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1189)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at com.gemstone.gemfire.internal.cache.tier.sockets.AcceptorImpl$1$1.run(AcceptorImpl.java:532)
at java.lang.Thread.run(Thread.java:724)

我不知道我做错了什么。如有任何帮助,我们将不胜感激。

最佳答案

抓得好!

我想补充一点,一般来说,基于数组和集合(应用程序域对象)的属性永远不应该为 null。可以为空,但不能为空。这对于迭代来说可能会出现问题(特别是 foreach 循环会导致相当模糊的 NPE,类似于自动装箱/拆箱中的 null 原始类型 Wrapper 对象),并且正如您所见,GemFire OQL。

不过,我同意如果 GemFire 能够确定查询问题的原因或者能够处理空引用,那么信息会更丰富、更有帮助。

有趣的是,这个问题可能是 GemFire 7.0.2 特有的。我刚刚使用 GemFire 7.0.2 和(最新的)GemFire 8.1.0 测试了这个场景。

在 7.0.2 中,发生了以下异常...

org.springframework.dao.InvalidDataAccessApiUsageException: Result object returned from GemfireCallback isn't a SelectResult: [UNDEFINED]
...

但是,使用 GemFire 8.1.0 运行时,OQL 语句(查询)按预期工作,即使嵌套 Collection 未在我的应用程序域对象上初始化...

class Customer ... {
Set<Address> addresses;
...
}

interface CustomerRepository implements GemfireRepository<Customer, Long> {
@Query("<trace> SELECT DISTINCT c FROM /Customers c, c.addresses a WHERE a.city = $1")
List<User> findCustomersInCity(String city);

}

然后...

customerRepo.findCustomersInCity("Portland");

我对我的客户进行了(重新)编码,以便仅在添加地址时才初始化“地址”集合,并且我在测试用例中使用了带地址和不带地址的客户组合。

因此,尽管 GemFire 8.x 似乎可以处理这个问题,但我仍然认为正确初始化对象是明智的。

关于java - 如何通过子对象唯一值或值集访问 Gemfire 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28488447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com