2016-08-04 7 views
0

私はABあたりのようなコードを書いた子要素を持つSpring CrudRepositoryクエリ?

{ 
    "contentTimestamp": 1470216079085, 
    "version": 12, 
    "content": [ 
    { 
     "text": "ABC", 
     "params": { 
     "TYPE": "TEXT" 
     } 
    } 
    ], 
    "readers": { 
    "u_id_1": 0, 
    "u_id_2": 0, 
    }, 
    "contributors": [ 
    { 
     "id": "u_id_1" 
    } 
    ] 
} 

Documentクラス

@Document 
public class ContentDoc implements Serializable{ 

    private static final long serialVersionUID = 1L; 


    @Id 
    private String id; 

    @Field 
    private Integer version = 12; 

    @Field 
    private List<Content> content = new ArrayList<>(); 

    @Field 
    private Map<String, Object> readers = new HashMap<>(); 

    //etc 

    //getter setter 

} 

を次のようにドキュメントサービス

@Service 
public interface ContentDocRepository extends CrudRepository<ContentDoc, String> { 

    public List<ContentDoc> findByReadersIn(String reader) throws Exception; 

} 

テストケース

@RunWith(SpringJUnit4ClassRunner.class) 
public class Tests { 

    @Autowired 
    private ContentDocRepository contentDocRepository; 

    @Test 
    public void cotentDocRepoTest(){ 

     List<ContentDoc> contents = contentDocRepository.findByReadersIn("u_id_1"); 
     Assert.assertNotNull(contents); 
     System.out.println(contents) 
    } 
} 

をCouchbaseのきいつでも空のarraylistを取得することはできません。

誰かが自分のコードで何がうまくいかないのかを知っています。子要素でクエリを実行するにはどうすればよいですか?

ありがとうございます。

答えて

0

長いRNDと実験の後、私は解決策を持って、

我々はメソッド名と子要素を見つけるための方法を持っていけないので、私たちは私の次の答え

手順どおりに行うために が必要になります。

1)次のようにcouchbaseでカスタムビューを作成します。

viewna私:findContentByUser

function (doc, meta) { 

    if(doc._class == "package.model.ContentDoc") { 
    for(var i=0; i < doc.contributors.length; i++){ 
     emit(doc.contributors[i].id, null); 
    } 

    } 
} 

2)サービス:最後に手に入れた結果:)

@Service 
public interface ContentDocRepository extends CrudRepository<ContentDoc, String> { 

    @View(viewName = "findContentByUser", designDocument="dev_content") 
    public List<ContentDoc> findByContributors_id(String id) throws Exception; 

} 

を以下のとおりIMPL方法で結合ビュー名とdesignDocument

関連する問題