How to add property to vertex property in java?

非 Y 不嫁゛ 提交于 2019-12-10 20:18:37

问题


I want to add property to a vertex property. In gremlin i add property "phone" to vertex property "places" that has value is "place1"

g.V(v).properties('places').hasValue('place1').property('phone',"123456789")

It worked ok without using transaction commit. But when i used this way in java code, it not worked. So in java code, how to add a property to vertex property? Thank for your help.


回答1:


You need to iterate() the traversal.

g.V(v).properties('places').hasValue('place1').property('phone',"123456789").iterate()

One way to think about: the original code snippet is the query, but then you still need to execute it.

Here's a full Gremlin Console example that shows the difference.

gremlin> graph = TitanFactory.open('inmemory'); g = graph.traversal()
==>graphtraversalsource[standardtitangraph[inmemory:[127.0.0.1]], standard]
gremlin> v = graph.addVertex('name','jenny','places','home')
==>v[4264]
gremlin> g.V(v).properties('places').hasValue('home')
==>vp[places->home]
gremlin> g.V(v).properties('places').hasValue('home').property('phone','867-5309'); 'traversal was not iterated'
==>traversal was not iterated
gremlin> g.V(v).properties('places').hasValue('home').properties()
gremlin> g.V(v).properties('places').hasValue('home').property('phone','867-5309').iterate(); 'iterated!'
==>iterated!
gremlin> g.V(v).properties('places').hasValue('home').properties()
==>p[phone->867-5309]
gremlin> graph.tx().commit()
==>null

You need to commit the transaction if you want the data to be persisted.



来源:https://stackoverflow.com/questions/34648009/how-to-add-property-to-vertex-property-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!