Custom N1QL query in couchbase using spring boot JAVA

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.

Hi,

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

1 Like

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

Hi,

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

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