Skip to content

Support querying@DocumentReference with QueryDsl #4037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ArayChou opened this issue Apr 27, 2022 · 0 comments
Closed

Support querying@DocumentReference with QueryDsl #4037

ArayChou opened this issue Apr 27, 2022 · 0 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@ArayChou
Copy link

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

@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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 27, 2022
@christophstrobl christophstrobl self-assigned this Apr 28, 2022
@christophstrobl christophstrobl added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 28, 2022
@mp911de 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
@mp911de mp911de added this to the 3.4.3 (2021.2.3) milestone Sep 16, 2022
mp911de pushed a commit that referenced this issue Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants