Announcement Announcement Module
No announcement yet.
@DbRef reference path can not be acess when Spring data mongo and QueryDSL. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @DbRef reference path can not be acess when Spring data mongo and QueryDSL.

    Hi Springer,

    I am learning Spring Mongo, and I am using Spring 3.2.2, Spring Data Mongo 1.2.1.

    The source codes under also include other data store. such JPA. I used Data JPA and Query DSL, it worked well.

    But switched to Mongo and QueryDSL, the @DBRef can not be queried.

    The test codes:

    	public void retrieveConferenceByQueryDSL() {
    		Conference conference = newConference();
    		conference.setName("Test JUD");
    		conference =;
    		log.debug("conference @" + conference);
    		String cid = conference.getId();
    		log.debug("saved conference id @" + cid);
    		assertTrue(null != cid);
    		QConference qconf = QConference.conference;
    		List<Conference> conferences = (List<Conference>) conferenceRepository
    		log.debug("conferences.size()@" + conferences.size());
    		assertTrue(1 == conferences.size());
    		List<Conference> conferences2 = (List<Conference>) conferenceRepository
    		log.debug("conferences2.size()@" + conferences2.size());
    		assertTrue(1 == conferences2.size());
    		Conference conf = conferenceRepository.findOne(cid);
    		Signup signup = newSignup();
    		signup =;
    		log.debug("signup @" + signup);
    		assertTrue(null != signup.getId());
    		List<Signup> signups = (List<Signup>) signupRepository
    		log.debug("signups.size()@" + signups.size());
    		assertTrue(1 == signups.size());
    		Signup signup2 = newSignup();
    		signup2.setComment("another comments");
    		signup2 =;
    		log.debug("signup2 @" + signup2);
    		assertTrue(null != signup2.getId());
    		List<Signup> signups2 = (List<Signup>) signupRepository
    		log.debug("signups2.size()@" + signups2.size());
    		assertTrue(2 == signups2.size());
    Query by QSignup.signup.conferenceXXXX alway return empty list.

    Confernce and Signup class.

    public class Conference {

    	private String id;

    	private Integer version;
    public class Signup {
    	private String id;
    	private Integer version;
    	private Conference conference;
    The QueryDSL apt maven plugin is configured correctly and the QConferecne and QSignup are generated as expected.
    Last edited by hantsy; May 17th, 2013, 02:10 AM.

  • #2
    it seems there is no way to use @Dbref field in QueryDSL directly now....

    I have to use MongoTemplate to do the qurey?

    How to use JoinBuilder like features which is provided in QueryDSL in Spring Data Mongo ???


    • #3
      I saw there is a SpringDataMongodbQuery in package which can use QueryDSL specific Join features etc...but it is not visible for developers.


      • #4
        I've had nothing but problems trying to use QueryDSL with mongodb. It allows you to do things, like querying on a dbref, that are not supported, yet are valid operations, without any errors or some kind of warning like "oh, this should work but we didn't make it yet, sorry, here's a null". Really annoying. I'm doing all my queries either with the MongoTemplate or via the naming conventions on the repository.