Reputation: 31
How to generate dynamic value of @Query
when have complex queries in Neo4jRepository ? Like:
@Repository
public interface StockRepository extends Neo4jRepository<StockNode,Long> {
@Query("match (n:stock) where n.name={aShareShortName} return n")
List<StockNode> getStockNodeByAShareShortName(@Param("aShareShortName") String aShareShortName);
@Query("match (n:stock) where n.{indexName}={indexContent} return n")
List<StockNode> getStockNodeByQueryProperty(@Param("indexName")String indexName,String indexContent);
}
The first method getStockNodeByAShareShortName
is Ok. But the second getStockNodeByQueryProperty
is failed. Is there any method to generate dynamic property keys in n.{xxx}
or n.?1
or n.:xx
?
Upvotes: 1
Views: 227
Reputation: 1738
for creating dynamic property or dynamic query you need to use session(import org.neo4j.ogm.session.Session;) then you can create dynamic query and append your where condition
String query="match (n:stock) where" DYNAMIC_FIELD+"=" +VALUE session.query(Map.class, query, queryParameters);
Upvotes: 1