Hi,
i got an Graph DB and at the moment, I'm trying to understand how to get the vertex properties.
I have a solution with relationships. But i think the "traversing" approach is not the best one.
managementService = new DatabaseManagementServiceBuilder(database).build();
graphDB = managementService.database(DEFAULT_DATABASE_NAME);
System.out.println("database opened for querying");
try (Transaction tx2 = graphDB.beginTx()) {
Node n1 = tx2.findNode(Labels.SINGLE_NODE, "name", node);
i tried the following approach. Without success. At the moment i think the properties also stored in separated Vertexes or i did a misstake.
String Name = n1.getProperty("name").toString();
System.out.println(n1.getProperty("name").toString());
String Dice = n1.getProperty("costs").toString();
System.out.println(n1.getProperty("costs").toString());
What you are doing looks correct. Did you get a result in 'n1'? If so, you should get a result from n1.getProperty("name").
What is happening that you think it is not working?
I used the Java API to develop a suite of traversal algorithms. To simplify things, I create wrapper objects for each type of node that contains the node plus accessor methods I need to access each specific property. This way I don't have to hard code the property names throughout the code, but have it specified only in the accessor method. I also have methods in the wrapper classes that implement my algorithms. You can then use OOP principles. In my constructors, I also get the relationships I will need for my algorithms and store them in lists. My algorithms are then written only using instance methods and properties.
Hi @glilienfield,
thanks for your respone.
The state n1.getProperty("name") is working fine. But the other one isn't working n1.getProperty("costs").toString(); . And at the moment i try to figure out why.
It is only with relationships possible to get the costs properties.
Is 'cost' a relationship attribute? If so, you need to get the relationships first. Then you can use the 'getProperty' method. Use one of the 'getRelationships" methods.
Let me know if you need specific help after reading the javadoc.