Java 带框架的Gremlin Groovy ClassCastException
我在使用与tinkerpop的帧关联的@GremlinGroovy注释时收到以下错误Java 带框架的Gremlin Groovy ClassCastException,java,groovy,gremlin,tinkerpop-frames,Java,Groovy,Gremlin,Tinkerpop Frames,我在使用与tinkerpop的帧关联的@GremlinGroovy注释时收到以下错误 java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.relations.CacheEdge cannot be cast to com.tinkerpop.blueprints.Vertex at com.tinkerpop.frames.structures.FramedVertexIterable$1.next(FramedVe
java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.relations.CacheEdge cannot be cast to com.tinkerpop.blueprints.Vertex
at com.tinkerpop.frames.structures.FramedVertexIterable$1.next(FramedVertexIterable.java:36)
at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processVertex(GremlinGroovyAnnotationHandler.java:75)
at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processElement(GremlinGroovyAnnotationHandler.java:114)
at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processElement(GremlinGroovyAnnotationHandler.java:30)
at com.tinkerpop.frames.FramedElement.invoke(FramedElement.java:83)
at com.sun.proxy.$Proxy81.getProxyCandidateEdgeFromPersonUuid(Unknown Source)
at com.company.prod.domain.Person$Impl.toImpl(Person.java:100)
....
以下行导致错误:
FooEdge fe = foo.getFooEdgeFromUuid(this.getUuid());
正在调用此方法的:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);
我还尝试了以下遍历(这会导致相同的错误):
然而,当我打开一个小精灵外壳来测试相同的精确遍历时,一切都很顺利。有没有想过是什么导致了这个问题?这并不是一个解决办法,而是一个答案。可以将gremlin与@JavaHandler注释一起使用,而不是使用@GremlinGroovy注释
@JavaHandler
void getFooEdgeFromUuid(String uuid);
abstract class Impl implements JavaHandlerContext<Vertex>, Foo {
public FooEdge getFooEdgeFromUuid(String uuid) {
return frameEdges(
gremlin().out("has")
.has("person-uuid", Tokens.T.eq, uuid)
.inE("has"),
FooEdge.class).iterator().next();
}
}
@JavaHandler
void getFooEdgeFromUuid(字符串uuid);
抽象类Impl实现JavaHandlerContext,Foo{
公共FooEdge getFooEdgeFromUuid(字符串uuid){
返回框边(
gremlin()out(“has”)
.has(“人uuid”,Tokens.T.eq,uuid)
.inE(“已”),
iterator().next();
}
}
这并不是一个解决方案的答案。可以将gremlin与@JavaHandler注释一起使用,而不是使用@GremlinGroovy注释
@JavaHandler
void getFooEdgeFromUuid(String uuid);
abstract class Impl implements JavaHandlerContext<Vertex>, Foo {
public FooEdge getFooEdgeFromUuid(String uuid) {
return frameEdges(
gremlin().out("has")
.has("person-uuid", Tokens.T.eq, uuid)
.inE("has"),
FooEdge.class).iterator().next();
}
}
@JavaHandler
void getFooEdgeFromUuid(字符串uuid);
抽象类Impl实现JavaHandlerContext,Foo{
公共FooEdge getFooEdgeFromUuid(字符串uuid){
返回框边(
gremlin()out(“has”)
.has(“人uuid”,Tokens.T.eq,uuid)
.inE(“已”),
iterator().next();
}
}
我认为您没有正确的用法,请提供该注释框架上的文档:
首先,请注意:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);
以及:
返回一个迭代器
,这也没有什么帮助,因为您需要在getFooEdgeFromUuid()中返回某种形式的列表
。假设您知道此查询将只返回且始终返回一条边,那么最好执行以下操作:
@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has').next()")
我之所以说“总是”,是因为如果没有它,你会得到一个NoTouchElementException
。这样,要正确对齐类型,可以执行以下操作:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid)}")
Iterable<FooEdge> getFooEdgesFromUuid(@GremlinParam("uuid") String uuid);
@GremlinGroovy(“it.outE('has').filter{it.inV().has('uuid',T.eq,uuid)}”)
Iterable getFooEdgesFromUuid(@GremlinParam(“uuid”)字符串uuid);
当然,所有这些都可能行不通,因为我在文档中看到了这样一句话:
可以使用Gremlin路径表达式作为
通过GremlinGroovyModule确定顶点邻接
换句话说,使用@GremlinGroovy
是为了返回带边框的顶点(而不是您正在尝试的边)。如果我上面建议的方法不起作用,那么使用@JavaHandler
的变通方法可能是您的最佳选择。我认为您没有正确的用法,请提供有关该注释框架的文档:
首先,请注意:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);
以及:
返回一个迭代器
,这也没有什么帮助,因为您需要在getFooEdgeFromUuid()中返回某种形式的列表
。假设您知道此查询将只返回且始终返回一条边,那么最好执行以下操作:
@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has').next()")
我之所以说“总是”,是因为如果没有它,你会得到一个NoTouchElementException
。这样,要正确对齐类型,可以执行以下操作:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid)}")
Iterable<FooEdge> getFooEdgesFromUuid(@GremlinParam("uuid") String uuid);
@GremlinGroovy(“it.outE('has').filter{it.inV().has('uuid',T.eq,uuid)}”)
Iterable getFooEdgesFromUuid(@GremlinParam(“uuid”)字符串uuid);
当然,所有这些都可能行不通,因为我在文档中看到了这样一句话:
可以使用Gremlin路径表达式作为
通过GremlinGroovyModule确定顶点邻接
换句话说,使用@GremlinGroovy
是为了返回带边框的顶点(而不是您正在尝试的边)。如果我上面建议的方法不起作用,那么使用@JavaHandler
的变通方法可能是最好的选择。我之所以使用hasNext()是因为过滤器闭包需要一个布尔结果,以确定特定顶点是否通过。我之所以使用hasNext()是因为这是因为过滤器闭包需要一个布尔结果来确定特定顶点是否通过。