Hi Everyone,
I got problem to make the spring data couchbase N1QL based repository methods working. Need urgent support.
Thanks in advance!!! – Allen
I followed the sample(http://projects.spring.io/spring-data-couchbase/) and created my own project.
- Created the “all” view - findAll and count works fine
- Created primary index (also tried normal index)
- Tried return List and Page result
- Tried spring data auto-generated query
- Tried Query annotation
So far, all N1QL based queries are not working - they just return empty. I ran similar query directly (select * from poiapp where country=‘Japan’), it returns data set.
Here is my setup:
Couchbase: Community 4.5 Beta
Spring Boot: 1.4.0.M3
Spring Data Couchbase: 2.1.1.RELEASE
Java client: 2.2.7
Here is the code snippet:
@Repository public interface PoiRepository extends CrudRepository<Poi, String> {
// backed by an auto-generated N1QL query public Page<Poi> findByName(String name, Pageable pageable); public long countByName(String name); public List<Poi> findByCountry(String country); public Page<Poi> findByCountryAndCity(String country, String city, Pageable pageable); public List<Poi> findByCountryAndCity(String country, String city); public Page<Poi> findByCountryAndCityAndName(String Country, String city, String name, Pageable pageable); public Page<Poi> findAll(Pageable pageable);
// Geo search example, backed by byLocation view @Dimensional(designDocument = "poiGeo", spatialViewName = "byLocation") public GeoPage<Poi> findByLocationNear(Point p, Distance r, Pageable pageable); @Dimensional(designDocument = "poiGeo", spatialViewName = "byLocation") public GeoPage<Poi> findByLocationWithin(Box cityBoundingBox, Pageable pageable); @Query("#{#n1ql.selectEntity} WHERE country = $1 AND #{#n1ql.filter}") public List<Poi> findAllCountry(String country); }
public Page<Poi> getPoi( @RequestParam("country") String country, @RequestParam("city") String city, Pageable pageable) { System.out.println("Country: " + country); System.out.println("City: " + city); return poiRepo.findByCountryAndCity(country, city, pageable); }