Hi, I’m using spring-data-couchbase 2.1.2, I redefined a repository with a custom query:
@Override
public List searchPortfolio() {
CouchbaseOperations template = templateProvider.resolve(PortfolioRepository.class, PortfolioDocument.class);
String statement = "select META(ipdb).id AS _ID, META(ipdb).cas AS _CAS, * " +
"from ipdb where _class = 'com.ipdb.datamodel.document.PortfolioDocument' AND title = 'dummytitle'";
SimpleN1qlQuery query = N1qlQuery.simple(statement);;
List<PortfolioDocument> portfolioDocuments = template.findByN1QL(query, PortfolioDocument.class);
....
}
template.findByN1QL(query, PortfolioDocument.class);
returns some PortfolioDocument
with all property to null except the id property. If I call template.findByOne(id);
the resulting object is ok.
Can you help me, please? Bye.
Have you tried with a “query derivation”? That is, don’t do a custom implementation but rather just add the following method signature to your repository’s interface:
public List<PortfolioDocument> findByTitleEquals(String title);
If the above works, then it’s probably an issue with you N1QL statement… although from a first look nothing particularly wrong stands out.
I have found a solution. The correct query is:
SELECT META(
ipdb).id AS _ID, META(
ipdb).cas AS _CAS,
ipdb.* FROM
ipdbWHERE ...
The best practice is to use the methods of N1qlUtils, you can look at the example below:
Statement statement = N1qlUtils.createSelectClauseForEntity(template.getCouchbaseBucket().name()).
from(Expression.i(template.getCouchbaseBucket().name()))
.where(".....");
createSelectClauseForEntity
and from
methods build the a part of query.
Bye,
Ah, so just missing the ipdb.
before the *
Note my “query derivation” suggestion above does use this utility class to generate the same query for you
Glad you found the solution!
Thanks but the where criteria is more complex, this is just a example. Bye.