我正在使用 spring-data-mongodb:1.2.0.RELEASE 和 QueryDSL:2.9.0。
我有两个类 A 和 B 如下:
@Document(collection = "A")
public class A {
public BigInteger id;
public Set<B> bSet;
}
@Document(collection = "B")
public class B {
public BigInteger id;
}
和一个存储库接口:
@Repository
public interface ARepository extends MongoRepository<A, BigInteger>, QueryDslPredicateExecutor<A>
{
}
我要做的是获取所有 A 文档,它们的 b 集合大小为一定大小。所以,我正在执行下一个查询:
aRepository.findAll(QA.a.bSet.size().loe(1));
我得到:
java.lang.UnsupportedOperationException: Illegal operation size(a.bSet)
at com.mysema.query.mongodb.MongodbSerializer.visit(MongodbSerializer.java:204)
at com.mysema.query.mongodb.MongodbSerializer.visit(MongodbSerializer.java:34)
at com.mysema.query.types.expr.NumberOperation.accept(NumberOperation.java:74)
at com.mysema.query.mongodb.MongodbSerializer.asDBValue(MongodbSerializer.java:75)
at com.mysema.query.mongodb.MongodbSerializer.asDBKey(MongodbSerializer.java:71)
at com.mysema.query.mongodb.MongodbSerializer.visit(MongodbSerializer.java:186)
at com.mysema.query.mongodb.MongodbSerializer.visit(MongodbSerializer.java:34)
at com.mysema.query.types.expr.BooleanOperation.accept(BooleanOperation.java:53)
at com.mysema.query.mongodb.MongodbSerializer.handle(MongodbSerializer.java:39)
at com.mysema.query.mongodb.MongodbQuery.createQuery(MongodbQuery.java:362)
at com.mysema.query.mongodb.MongodbQuery.createCursor(MongodbQuery.java:272)
at com.mysema.query.mongodb.MongodbQuery.createCursor(MongodbQuery.java:267)
at com.mysema.query.mongodb.MongodbQuery.list(MongodbQuery.java:253)
at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:93)
at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:333)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy68.findAll(Unknown Source)
at com.shunra.server.test.filesmanagement.TestFilesRepository.tmp(TestFilesRepository.java:248)
总结一下,我需要一个例子/解释。