【问题标题】:How to add property to vertex property in java?如何在java中将属性添加到顶点属性?
【发布时间】:2016-01-07 05:34:32
【问题描述】:

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

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

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

【问题讨论】:

  • 您上面的代码似乎对 TinkerGraph 有效。你得到了什么异常?
  • 它不会抛出异常,当我想保存属性时它不起作用

标签: java titan gremlin tinkerpop3


【解决方案1】:

你需要iterate()进行遍历。

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

一种思考方式:原来的代码sn-p就是查询,但是接下来还是需要执行。

这是一个完整的 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

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

【讨论】:

  • 还有一个问题,如何删除顶点属性值为'home''?这样它就不起作用 g.V(v).properties('places').hasValue('home').drop() 。再次感谢您
  • 和以前一样的答案,你需要iterate(),所以g.V(v).properties('places').hasValue('home').drop().iterate()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-02
  • 1970-01-01
相关资源
最近更新 更多