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

Mic*_*elP 3 java gremlin titan tinkerpop3

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

g.V(v).properties('places').hasValue('place1').property('phone',"123456789")
Run Code Online (Sandbox Code Playgroud)

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

Jas*_*rad 5

你需要iterate()遍历.

g.V(v).properties('places').hasValue('place1').property('phone',"123456789").iterate()
Run Code Online (Sandbox Code Playgroud)

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

这是一个完整的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
Run Code Online (Sandbox Code Playgroud)

如果要保留数据,则需要提交事务.