package com;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.graphdb.Transaction;
public class hotspots {
public static enum RelTypes implements RelationshipType
{
PERSON
}
public static void main(String[] args) {
GraphDatabaseService graphdb = new EmbeddedGraphDatabase("target/dbnew");
Transaction tx = graphdb.beginTx();
try{
Node n1 = graphdb.createNode();
Node n2 = graphdb.createNode();
n1.setProperty("name","Melwin");
n2.setProperty("name","Louis");
Relationship rel1 = graphdb.getReferenceNode().createRelationshipTo( n1, RelTypes.PERSON );
Relationship rel2 = graphdb.getReferenceNode().createRelationshipTo( n2, RelTypes.PERSON );
tx.success();
}
catch (Exception e) {
tx.failure();
}
finally{
tx.finish();
}
graphdb.shutdown();
System.out.println("Success");
}
}
这是我创建的一个小型数据库,我在 Neoclipse 中查看它。每次我运行这段代码并在 Neoclipse 中查看它时,我都会得到双倍的节点和关系。换句话说,我得到了另外两个具有相同名称和关系的节点。