Note that there are some explanatory texts on larger screens.

plurals
  1. POMapResult with CypherDSL
    text
    copied!<p>I have this query, built with cypher-dsl (b/c the <code>MATCH</code>-clause is dynamic) and the result-set contains nodes which are represented by <code>@NodeEntity</code> annotated POJOs (amongst other columns).</p> <p>My question is: Is there a way to have the result of a dynamic (non-annotated) query, wrapped into a <code>@MapResult</code> (or a regular Map with NodeEntities as values)?</p> <p>The following approach doesn't seem to work, because the inferred type of <code>GraphRepository</code> has to be either a Node- or RelationshipEntity:</p> <pre><code>@NodeEntity public class Customer { @GraphId Long id; ... } @MapResult public interface CustomerQueryResult { @ResultColumn("cust") Customer getCustomer(); @ResultColumn("val1") int getVal1(); ... } public interface CustomerQueryRepository extends GraphRepository&lt;CustomerQueryResult&gt; { } @Service public class SearchService { private CustomerQueryRepository repo; ... @Inject public SearchService(CustomerQueryRepository repo, ...) { this.repo = repo; ... } public Iterable&lt;CustomerQueryResult&gt; search(...) { Execute cyQuery = start(...) ... .returns( "cust", "val1", ... ); return this.repo.query(cyQuery.toString(), ...); } } </code></pre> <p>I'm using spring-data-neo4j version <code>2.3.0.M1</code></p> <p>thanks for your help, in advance</p> <hr> <p><strong>Update:</strong> Ok, using <code>Neo4jTemplate</code>'s <code>query</code> and <code>convert</code> methods, do the job:</p> <pre><code>@Inject public SearchService(Neo4jTemplate template, ...) { this.template = template; ... } public List&lt;QueryResult&gt; search(...) { List&lt;QueryResult&gt; result = new ArrayList&lt;&gt;(); Execute cyQuery = start(...) ... .returns( "cust", "val1", ... ); for (Map&lt;String, Object&gt; res : this.template.query(cyQuery.toString(), ...)) { Customer cust = this.template.convert((NodeProxy)res.get("cust"), Customer.class); result.add(new QueryResult() .setCustomer(cust) ... ); } return result; } </code></pre> <p>(assuming that Customer is a class now and not an interface anymore)</p> <p>However, is there maybe a better way to do it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload