ClassCastException while fetching edge property va

2019-07-14 18:33发布

问题:

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()