Results 1 to 7 of 7

Thread: Spring-data mongodb repository and inheritance

  1. #1

    Question Spring-data mongodb repository and inheritance

    I have created an user class like that :

    Code:
    public class User {
        /**
         * The list of roles for the user
         */
        private List<String> roles;
        /**
         * The login information
         */
        private ICredentials credentials;
    
        /*---- the constructors and getters/setters are omitted ---*/
    }
    The ICredentials interface :

    Code:
    public interface ICredentials {
    }
    One implementation :

    Code:
    public class LoginPassword implements ICredentials {
        /**
         * The login of the user
         */
        protected String login;
    
        /**
         * The password of the user
         */
        protected String password;
    
        /*---- the constructors and getters/setters are omitted ---*/
    }
    Now, I have created a repository to find a user from credentials :

    Code:
    public interface MongoUserRepository extends MongoRepository<User, String> {
        List<User> findByCredentials(ICredentials credentials);
        List<User> findByCredentialsEquals(ICredentials credentials);
    }
    Spring logs this (for both requests) : org.springframework.data.mongodb.core.MongoTemplat e [DEBUG] find using query: { "credentials" : { "login" : "test" , "password" : "test"}} fields: null for class: class xxx.User in collection: user

    And it doesn't found anything... It seems that it doesn't found anything because the "_class" attribute is not written is the request. I think the good request should be: { "credentials" : {"_class":"xxx.LoginPassword", "login" : "test" , "password" : "test"}}

    Is something I doing wrong ? Am I missing something ?

    Thanks

    I use spring mvc 3.2.0, spring-data-commons-core 1.4.0, spring-data-mongodb 1.1.1 and mongo-java-driver 2.10.1 (I have updated all libraries to the latest version to be sure it wasn't a bug already fixed but no success)

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    493

    Default

    What you see is correct and should work. Is there a chance you provide a sample project I can have a look at?

  3. #3

    Default

    Ok I have done a minimal project available here:
    http://dl.free.fr/uvI6XZSlk
    Just deploy it on Apache and open the readme to execute requests

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    493

    Default

    Sorry, I am not going to download something from an obscure website , some sample repo on GitHub is sufficient. Also, please make it a minimal test case we can run through mvn clean test.

    Thanks!

  5. #5

  6. #6

    Default

    I have no feedback on this problem. Have you analyzed the example ?

  7. #7
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    493

    Default

    I've created and fixed DATAMONGO-600 [0] which will be available in upcoming 1.1.2 and 1.2 releases. Unfortunately our build servers currently seem to choke on some MongoDB instance issues but you should see your test cases succeeding running against a locally built 1.2.0.BUILD-SNAPSHOT. You might wanna remove the Spring Data Commons declaration from your pom and rather rely on the one pulled in transitively by Spring Data MongoDB.

    [0] https://jira.springsource.org/browse/DATAMONGO-600

Tags for this Thread

Posting Permissions

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