You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Document
public class Kid {
@Id
private String id;
private String name;
@DocumentReference
private Mother mother;
@DBRef
private Father father;
// ommiting setters and getters
}
@Autowired
private KidRepository repository;
public void test() {
// @DBRef annotated field works
repository.findAll(QKid.kid.father.id.eq(this.fatherId)).forEach(System.out::println);
//TODO To query @DocumentReference annotated field Kid.mother won't work
repository.findAll(QKid.kid.mother.id.eq(this.motherId)).forEach(System.out::println);
}
Field Kid.mother is annotated with @DocumentReference. repository.findAll(QKid.kid.mother.id.eq(this.motherId)) will throw exception, it should work just as @DBREF.
Exception in thread "main" java.lang.IllegalArgumentException: The referenced property has to be mapped with @DBRef!
at org.springframework.util.Assert.isTrue(Assert.java:121)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:590)
at org.springframework.data.mongodb.repository.support.SpringDataMongodbSerializer.asReference(SpringDataMongodbSerializer.java:149)
at org.springframework.data.mongodb.repository.support.SpringDataMongodbSerializer.convert(SpringDataMongodbSerializer.java:189)
at com.querydsl.mongodb.document.MongodbDocumentSerializer.visit(MongodbDocumentSerializer.java:108)
at com.querydsl.mongodb.document.MongodbDocumentSerializer.visit(MongodbDocumentSerializer.java:41)
at com.querydsl.core.types.OperationImpl.accept(OperationImpl.java:88)
at com.querydsl.mongodb.document.MongodbDocumentSerializer.handle(MongodbDocumentSerializer.java:44)
at com.querydsl.mongodb.document.AbstractMongodbQuery.createQuery(AbstractMongodbQuery.java:206)
at org.springframework.data.mongodb.repository.support.SpringDataMongodbQuery.createQuery(SpringDataMongodbQuery.java:248)
at org.springframework.data.mongodb.repository.support.SpringDataMongodbQuery.createQuery(SpringDataMongodbQuery.java:240)
at org.springframework.data.mongodb.repository.support.SpringDataMongodbQuery.fetch(SpringDataMongodbQuery.java:161)
at org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor.findAll(QuerydslMongoPredicateExecutor.java:113)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker$RepositoryFragmentMethodInvoker.lambda$new$0(RepositoryMethodInvoker.java:289)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:529)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:285)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:639)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:163)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:138)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at jdk.proxy2/jdk.proxy2.$Proxy53.findAll(Unknown Source)
at test.QueryDslTest.test(QueryDslTest.java:22)
at test.ExampleApplication.main(ExampleApplication.java:15)
Thanks & Regards.
The text was updated successfully, but these errors were encountered:
mp911de
changed the title
Querying @DocumentReference annotated field with QueryDSL fails: java.lang.IllegalArgumentException: The referenced property has to be mapped with @DBRef!
Support querying@DocumentReference with QueryDsl
Sep 16, 2022
Hello, here is the demo project: https://github.com/ArayChou/spring-data-mongodb-test. Run the class test.ExampleApplication to start it. (it needs a local default installed MongoDB server)
spring-data-mongodb: 3.3.4
querydsl-mongodb: 5.0.0
mongodb-driver-sync: 4.4.2
Field Kid.mother is annotated with @DocumentReference. repository.findAll(QKid.kid.mother.id.eq(this.motherId)) will throw exception, it should work just as @DBREF.
Thanks & Regards.
The text was updated successfully, but these errors were encountered: