2014-04-08 5 views
1

나는 no에 기반한 자바 클래스에서 독특한 neo4j 관계를 만들고있다. 데이터베이스의 열 값 중. 열 값은 "interface_name을"각 relationship.My 코드에 할당됩니다자바에서 Neo4j 관계 만들기

while (rs.next()){ 
    String rel = rs.getString("Interface_Name"); 
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("D://My Graph"); 
    Transaction tx = graphDb.beginTx();  
    try {  
     RelationshipType rel = DynamicRelationshipType.withName(rel); **//Gives error since rel is string** 
     ..... 
     tx.success(); 
    } 
} 

가 어떻게 DB에서 열 값을 기준으로 관계 유형을 만들 수 있습니다 내부 루프 관계 유형은 DB 값에 따라 생성을하셔야합니다 동안?.

답변

1

노드를 만들지 않고는 관계를 만들 수 없습니다. 시작 노드와 끝 노드가 필요합니다. 또한 발생하는 모든 열에 대해 새 GraphDatabaseService을 만들지 마십시오. 귀하의 코드는 다음과 같을 수 있습니다 :

GraphDatabaseService graphDb = new EmbeddedGraphDatabase("D://My Graph"); 
while (rs.next()){ 
    String rel = rs.getString("Interface_Name"); 
    try (Transaction tx = graphDb.beginTx()) { 
     RelationshipType relType = DynamicRelationshipType.withName(rel); 
     graphDb.createNode().createRelationshipTo(graphDb.createNode(), relType); 
     tx.success(); 
    } 
} 
+0

Ok하지만 동일한 "rel"변수를 두 번 정의하면 오류가 발생합니다. 그것을 고치는 방법? 안내해주세요 – ashwini

+0

정확한 예외 메시지는 무엇입니까? – tstorms

+0

RelationshipType rel = ....에서 "rel"변수의 이름을 바꿉니다.이 줄은 이미 정의 했으므로 입니다. String rel = rs.next(). getString ("Interface_Name"); – ashwini