Custom N1QL query in couchbase using spring boot JAVA

n1ql

#1

Hi

I was playing with couchbase using http://www.baeldung.com/spring-data-couchbase.But I am stuck with running custom N1QL queries.

I wrote this in repository

@Query(“SELECT l.created_on,l.is_public,l.list_id,l.list_name,l.type,l.user_id,META(u).id AS _ID, META(u).cas AS _CAS FROM lists USE INDEX(lists USING GSI) WHERE type=‘list’ AND user_name=$userName AND list_name=$listName”)
public Lists checkListName(@Param(“userName”) String userName, @Param(“listName”) String listName);

But I am getting this

Unable to retrieve enough metadata for N1QL to entity mapping, have you selected _ID and _CAS?

Is their another way or what should I do to run this query.


#2

Hi,

I see META(u).id AS _ID, what does u refer to in the query, shouldn’t it be META(lists).id


#3

Thanks I was able to figure it out, what was wrong with my query.


#4

Hi,

And what was wrong with your query ? I’m facing to the same issue


#5

@Antho Use Custom template instead inbuilt JPA as writing custom N1QL give you more command over using JPA. l will be happy to help .