2016-01-07 189 views
3

我想将属性添加到顶点属性。在小鬼我添加属性“手机”到具有价值顶点属性“地方”是“PLACE1”如何将属性添加到Java中的顶点属性?

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

它不使用事务提交的工作确定。但是当我在java代码中使用这种方式时,它不起作用。那么在java代码中,如何将属性添加到顶点属性? 感谢您的帮助。

+0

上面的代码似乎对TinkerGraph有效。你得到的例外是什么? –

+0

它不会抛出异常,它只是不工作,当我想保存一个属性 – MichaelP

回答

4

你需要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 

如果您希望数据持久化,则需要提交事务。

+0

还有一个问题,如何删除顶点属性有价值'家'?通过这种方式,它不起作用g.V(v).properties('places')。hasValue('home')。drop()。再次感谢你 – MichaelP

+0

和以前一样,你需要'iterate()',所以'g.V(v).properties('places')。hasValue('home')。drop()。iterate()'。 –

+0

它的工作原理,谢谢。 – MichaelP