Results 1 to 3 of 3

Thread: How to implement a custom MongoDB repository

  1. #1
    Join Date
    Mar 2010
    Posts
    9

    Default How to implement a custom MongoDB repository

    Hi there,
    I'm trying to implement a custom repository for a MongoDB entity, but it doesn't seem to be recognized...
    I have this :

    Code:
    @RooRepositoryMongo(domainType = Organization.class)
    public interface OrganizationRespository  {
        List<Organization> findAll();
        long countByDomain(String domain);
    }
    First, I tried with and abstract class :

    Code:
    public abstract class OrganizationRepositoryImpl extends OrganizationRepository {
       @Autowired MongoTemplate mongoTemplate;  
    
       public long countByDomain(String domain) {
          ....
       }
    }
    No luck, I always get a "no property count found for type long" at runtime. (The truth is that I can't have the count*() methods to work. That's why I try to implement it myself. But I'll need to implement custom query methods anyway)

    I also tried with a custom interface (OrganizationRepositoryCustom) like so :

    Code:
    @RooRepositoryMongo(domainType = Organization.class)
    public interface OrganizationRespository extends OrganizationRepositoryCustom {
        List<Organization> findAll();
    }
    
    public interface OrganizationRepositoryCustom {
       public long countByDomain(String domain);
    }
    
    public class OrganizationRepositoryCustomImpl implements OrganizationRepositoryCustom {
    	@Autowired
    	MongoTemplate mongoTemplate;
    	
    	@Override
    	public long countByDomain(String domain) {
    	   ...
    	}
    }
    No luck. Same error. Every time I invoke an interface method, it seems proxied behind the scenes by this dymanic repo implementation. My implementation does not work...
    So, what's the right way ? Am I missing some annotation parameters (I think Roo makes things even worse to see clear) ?

    Thanks in advance,
    Bardamu

  2. #2
    Join Date
    Mar 2010
    Posts
    9

    Default

    Ok, I did not follow the conventions. The custom implementation class should be named OrganizationRepositoryImpl and not OrganizationRepositoryCustomImpl.

  3. #3
    Join Date
    Jul 2007
    Posts
    26

    Default

    Do you have this line in your mongo config context file?
    <mongo:repositories base-package="com.xxx.yyy.repositories"
    mongo-template-ref="mongoTemplate" />

    BR//Bahman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •