Announcement Announcement Module
Collapse
No announcement yet.
@DbRef reference path can not be acess when Spring data mongo and QueryDSL. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    https://github.com/hantsy/spring-san...ets/data-mongo


    The source codes under https://github.com/hantsy/spring-sanbox 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:

    Code:
    @Test
    	public void retrieveConferenceByQueryDSL() {
    		Conference conference = newConference();
    		conference.setSlug("test-jud");
    		conference.setName("Test JUD");
    		conference.getAddress().setCountry("US");
    		conference = conferenceRepository.save(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
    				.findAll(qconf.slug.eq("test-jud"));
    		log.debug("conferences.size()@" + conferences.size());
    		assertTrue(1 == conferences.size());
    
    		List<Conference> conferences2 = (List<Conference>) conferenceRepository
    				.findAll(QConference.conference.address.country.eq("CN"));
    		log.debug("conferences2.size()@" + conferences2.size());
    		assertTrue(1 == conferences2.size());
    
    		Conference conf = conferenceRepository.findOne(cid);
    
    		Signup signup = newSignup();
    		signup.setConference(conf);
    
    		signup = signupRepository.save(signup);
    		log.debug("signup @" + signup);
    
    		assertTrue(null != signup.getId());
    
    		List<Signup> signups = (List<Signup>) signupRepository
    				.findAll(QSignup.signup.conference.eq(conf));
    		log.debug("signups.size()@" + signups.size());
    		assertTrue(1 == signups.size());
    
    		Signup signup2 = newSignup();
    		signup2.setComment("another comments");
    		signup2.setConference(conf);
    
    		signup2 = signupRepository.save(signup2);
    		log.debug("signup2 @" + signup2);
    
    		assertTrue(null != signup2.getId());
    
    		List<Signup> signups2 = (List<Signup>) signupRepository
    				.findAll(QSignup.signup.conference.eq(conf));
    		log.debug("signups2.size()@" + signups2.size());
    		assertTrue(2 == signups2.size());
    
    	}
    Query by QSignup.signup.conferenceXXXX alway return empty list.

    Confernce and Signup class.

    Code:
    @Document
    public class Conference {
    
    	@org.springframework.data.annotation.Id
    	private String id;
    
    	@org.springframework.data.annotation.Version
    	private Integer version;
    Code:
    @Document
    public class Signup {
    
    	@Id
    	private String id;
    
    	@Version
    	private Integer version;
    
    	@DBRef
    	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, 03: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 ???

    Comment


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

      Comment


      • #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.

        Comment

        Working...
        X