Announcement Announcement Module
Collapse
No announcement yet.
Spring-data mongodb repository and inheritance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    What you see is correct and should work. Is there a chance you provide a sample project I can have a look at?

    Comment


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

      Comment


      • #4
        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!

        Comment


        • #5
          https://github.com/aurelien-baudet/s...mongo-repo-bug

          Comment


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

            Comment


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

              Comment

              Working...
              X