2013-01-11 36 views
2

我創建了一個類用戶類這樣的:彈簧數據MongoDB的倉庫和繼承

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 ---*/ 
} 

的ICredentials接口:

public interface ICredentials { 
} 

一個實現:

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 ---*/ 
} 

現在,我創建了一個信息庫,以找到憑據的用戶:

public interface MongoUserRepository extends MongoRepository<User, String> { 
    List<User> findByCredentials(ICredentials credentials); 
    List<User> findByCredentialsEquals(ICredentials credentials); 
} 

春季將這一情況記錄(對於兩個請求): org.springframework.data.mongodb.core.MongoTemplate [DEBUG]發現使用查詢:{ "credentials" : { "login" : "test" , "password" : "test"}}字段:空類:在集合類xxx.User:用戶

而且它並沒有發現什麼...看來,它並沒有發現任何東西,因爲「_class」屬性不寫是請求。我認爲好的要求應該是: { "credentials" : {"_class":"xxx.LoginPassword", "login" : "test" , "password" : "test"}}

是我做錯了嗎?我錯過了什麼嗎?

感謝

我使用Spring MVC的3.2.0,彈簧數據公共核心1.4.0,彈簧數據的MongoDB 1.1.1和蒙戈的Java驅動程序2.10.1(我已經全部更新庫到最新版本,以確保它不是

回答

2

你嘗試添加@Document(集合=「用戶」)以上的ICredentials接口已經修正了一個錯誤,但沒有成功)?

1

它,當你不使用註釋爲您的文檔發生

@Document(collection = "example") 
public class Example{ 

    @Id 
    private String id; 

    //getter and setters 
}