ClassCastException while fetching edge property value bewteen two vertices

不问归期 提交于 2019-12-24 01:41:39

问题


I am trying to fetch edge property value between two vertices and getting below exception

java.lang.ClassCastException: java.lang.String cannot be cast to scala.runtime.Nothing$

Env: Titan InMemory

Code :

val age = Key[Int]("age")

 A ---("knows",age -> 10) --> B

Gremlin query:

graph.traversal().V().has("ID", "A").bothE("knows").as("x").otherV()
      .has("ID", "B").select("x").properties("age").headOption().get

output : p[age->10]

graph.traversal().V().has("ID", "A").bothE("knows").as("x").otherV()
          .has("ID", "B").select("x").label().head()

output : knows

graph.traversal().V().has("ID", "A").bothE("knows").as("x").otherV()
      .has("ID", "B").select("x").values("age").head()

Output:

java.lang.ClassCastException: java.lang.String cannot be cast to scala.runtime.Nothing$

Any idea when i try to fetch property value , i am getting this error

Same works with gremlin console http://gremlinbin.com/bin/view/58044fa931772


回答1:


Not sure this is correct solution. This resolved my problem.

I was inserting integer value to edge property

Before: mgmt.makePropertyKey("age").dataType(classOf[String]).cardinality(Cardinality.SET).make()

After :

mgmt.makePropertyKey("age").dataType(classOf[Integer]).cardinality(Cardinality.SET).make()

After changing this , below error was occuring

java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.runtime.Nothing$

Before :

val age_value = graph.traversal().V().has("ID", "A").bothE("knows").as("x").otherV()
      .has("ID", "B").select("x").values("age").head()

After :

val age_value:Integer = graph.traversal().V().has("ID", "A").bothE("knows").as("x").otherV()
      .has("ID", "B").select("x").values("age").head()


来源:https://stackoverflow.com/questions/40078365/classcastexception-while-fetching-edge-property-value-bewteen-two-vertices

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