spring-projects / spring-data-examples

Spring Data Example Projects
Apache License 2.0
5.19k stars 3.4k forks source link

querydsl of mongodb execute Relational query errors #209

Closed marskobe closed 7 years ago

marskobe commented 8 years ago

I hava two related entities like this: `
 @Document(collection = "lmt_limit")
 public class LimitEntity implements Serializable {
 /*
 * 主键
 /

@Id

private Long id;



 /**
   * 关联Entity:封禁原因
   */
  
@DBRef
  
private ReasonEntity reason;



}



@Document(collection = "lmt_reason")
 public class ReasonEntity implements Serializable {
 /*
 * 主键
 /

@Id

private Integer id;



/**
   * 封禁原因message值
   */
  
private String message;



}
 ` LimitEntity is @DBRef
 ReasonEntity, and in my mongodb database's lmt_limit Collection I hava two Document like this:

/* 0 */ { "_id" : NumberLong(1), "_class" : "tv.acfun.cloud.service.limit.entity.LimitEntity", "reason" : { "$ref" : "lmt_reason", "$id" : 1 } }

/* 1 */ { "_id" : NumberLong(2), "_class" : "tv.acfun.cloud.service.limit.entity.LimitEntity", "reason" : { "$ref" : "lmt_reason", "$id" : 2 } }

so I want to query LimitEntity by ReasonEntity's attribute like this:

` BooleanBuilder booleanBuilder = new BooleanBuilder(); booleanBuilder.and(QLimitEntity.limitEntity.reason.id.eq(1));

Paginate page = new Paginate(limitRepository.findAll(booleanBuilder, pageRequest)); ` My pageRequest has pageNum as 0, and pageSize as 20, Theoretically the result page should has one data record, but the truth is I have get nothing. so how does this happen ??

My querydsl version is 3.7.4.

Finally I rememberd Original I can get the Correct results,but I don't know why is it suddenly not!!

odrotbohm commented 8 years ago

Would you mind rather using StackOverflow for general questions of usage? We use the tracker to keep track of bugs, new features, etc.

marskobe commented 8 years ago

ok, thank you

The question is almost the same as http://stackoverflow.com/questions/21166580/spring-data-mongodb-querydsl-dbref-exception

Can you help me solve the problem? thank you very much.