In my SDN 4 project I have a following entitites:
@NodeEntity
public class Characteristic extends Authorable {
private final static String CONTAINS = "CONTAINS";
private final static String DEFINED_BY = "DEFINED_BY";
private String name;
private String description;
@Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
private Decision owner;
}
@NodeEntity
public class Decision extends Commentable {
private final static String DEFINED_BY = "DEFINED_BY";
@Relationship(type = DEFINED_BY, direction = Relationship.INCOMING)
private Set<Characteristic> characteristics = new HashSet<>();
}
@RelationshipEntity(type = "DECISION_CHARACTERISTIC")
public class DecisionCharacteristic {
@GraphId
private Long id;
@StartNode
private Decision decision;
@EndNode
private Characteristic characteristic;
private Object value;
}
I need to select a Decision
nodes that match the specific characteristics.
I have created a following Cypher query:
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} MATCH (childD)-[rdc:DECISION_CHARACTERISTIC]->(characteristic:Characteristic) WHERE ( ( ( id(characteristic) = 138 AND (rdc.value > 15000.32)) AND ( id(characteristic) = 138 AND (rdc.value < 50000.32)) ) AND ( id(characteristic) = 139 AND (rdc.value = 'Commercial')) ) WITH childD, ru, u RETURN childD
but this query works wrong. I need to select a Decision nodes that for characteristic with id=138
has a value between 15000.32 and 50000.32
and for characteristic with id=139
has exact value = 'Commercial'
.
Where I'm wrong in my query and how to transform it in order to get working as expected ?
UPDATED
I have a following nodes:
DecisionCharacteristic neo4jPriceDecisionCharacteristic = new DecisionCharacteristic(neo4jDecision, priceCharacteristic, new Double(10000.32d));
decisionCharacteristicRepository.save(neo4jPriceDecisionCharacteristic);
DecisionCharacteristic oraclePriceDecisionCharacteristic = new DecisionCharacteristic(oracleDecision, priceCharacteristic, new Double(35000.2d));
decisionCharacteristicRepository.save(oraclePriceDecisionCharacteristic);
assertNotNull(neo4jPriceDecisionCharacteristic);
assertNotNull(neo4jPriceDecisionCharacteristic.getId());
DecisionCharacteristic neo4jLicenseDecisionCharacteristic = new DecisionCharacteristic(neo4jDecision, licenseCharacteristic, "Commercial");
decisionCharacteristicRepository.save(neo4jLicenseDecisionCharacteristic);
DecisionCharacteristic orientLicenseDecisionCharacteristic = new DecisionCharacteristic(orientDecision, licenseCharacteristic, "Free");
decisionCharacteristicRepository.save(orientLicenseDecisionCharacteristic);
DecisionCharacteristic oracleLicenseDecisionCharacteristic = new DecisionCharacteristic(oracleDecision, licenseCharacteristic, "Commercial");
decisionCharacteristicRepository.save(oracleLicenseDecisionCharacteristic);
IDs:
priceCharacteristic ID: 138
licenseCharacteristic ID: 139
I'm trying to get a Decision
nodes with a following query:
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} MATCH (childD)-[rdc:DECISION_CHARACTERISTIC]->(characteristic:Characteristic) WHERE ( id(characteristic) = 138 AND ( id(characteristic) = 138 AND ( (rdc.value > 15000.32)) AND ( (rdc.value < 50000.32)) ) OR ( id(characteristic) = 139 AND (rdc.value = 'Commercial')) ) RETURN childD
I expect that only oracleDecision
node matches this condition but it returns two nodes:
Neo4j
Oracle
Where I'm wrong ?