如何在java中向vertex属性添加属性?

时间:2016-01-07 05:34:33

标签: java titan gremlin tinkerpop3

我想将属性添加到顶点属性。在gremlin中,我将属性“phone”添加到顶点属性“places”,其值为“place1”

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

没有使用事务提交它工作正常。但是当我在java代码中使用这种方式时,它没有用。那么在java代码中,如何向vertex属性添加属性? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:5)

您需要iterate()遍历。

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

一种思考方式:原始代码段是查询,但您仍然需要执行它。

这是一个完整的Gremlin控制台示例,显示了差异。

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

如果您希望保留数据,则需要提交事务。