2017-11-09 14 views
0

少なくとも1つのタグをパラメータとして含む最初のオブジェクトを取得したいと思います。リストデータを持つスプリングデータcouchbase N1QL

@Query("#{#n1ql.selectEntity} WHERE SOME t IN tags SATISFIES t IN [\"#{#currentTags}\"] " + 
     "END AND #{#n1ql.filter} LIMIT 1") 
RecipeEntry findFirstContainingTags(@Param("currentTags")List<String> tags); 

しかし、生成されたN1QLクエリは

"SELECT * FROM contents WHERE SOME t IN tags SATISFIES t IN ["tag1,tag2"] END LIMIT 1" 

予想クエリはので、私は私のパラメータcurrentTagsは、[ "TAG1"、 "タグ2" に変換されることを期待し

"SELECT * FROM contents WHERE SOME t IN tags SATISFIES t IN ["tag1","tag2"] END LIMIT 1" 

です] not ["tag1、tag2"]

Springデータでこのクエリを生成する手段はありますか?詳細については、私がやっていること以下

+0

このクエリーを試してみましたか?@Query( "#{#n1ql.selectEntity}"いくつかのINタグが満足している場所:#{#currentTags} + "END AND####n1ql.filter ORDER BY creationDate DESC LIMIT 1 ") – ozgur

+0

引用符を削除するとどうなりますか? (SATISFIES t IN [#{#currentTags}]) – marco

+0

Jpa Query IN ["params"]は使用できません。これはネイティブクエリではありません。 – ozgur

答えて

0

  • 私は、パラメータ

サービスとしてJSON付けJSON

  • に文字列の私のリストを変換するために、ジャクソンobjectMapperを使用します。

    public RecipeEntry findMostRecentWithAtLeastTags(List<String> tags) { 
        RecipeEntry recipeEntry = null; 
        try { 
         String tagsArray = objectMapper.writeValueAsString(tags); 
         recipeEntry = ((RecipeQueryRepository) this.queryRepository).findMostRecentWithAtLeastTags(tagsArray); 
        } catch (Exception e) { 
         log.error("Error while retrieving most recent recipe with given tags", e); 
        } 
    
        return recipeEntry; 
    } 
    

    レポジトリ:

    @Query("#{#n1ql.selectEntity} WHERE status = 'PUBLISHED' AND (EVERY t IN #{#currentTags} SATISFIES t IN tags END) " + 
         "AND #{#n1ql.filter} ORDER BY publishDate DESC LIMIT 1") 
    RecipeEntry findMostRecentWithAtLeastTags(@Param("currentTags") String tags); 
    
  • 関連する問題