使用spring-data和QueryDSL查询集合属性大小

时间:2013-06-05 16:42:14

标签: querydsl spring-data-mongodb

我正在使用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>
{

}

我要做的是获取他们的b集合大小为一定大小的所有A文档。 所以,我正在执行下一个查询:

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)

总结一下,我需要一个例子/解释。

1 个答案:

答案 0 :(得分:1)

Querydsl目前不支持此功能。随意在GitHub创建一张票。