2015-09-30 33 views
1

我在使用與tinkerpop的框架關聯的@GremlinGroovy註釋時收到以下錯誤。Gremlin Groovy帶框架的ClassCastException

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

我也試過以下遍歷(這會導致同樣的錯誤):

@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has')") 

Howeve r,當我打開一個gremlin shell來測試相同的確切遍歷時 - 一切都很順利。對可能導致問題的任何想法?

回答

0

這不是一個答案,因爲它是一個解決方法。可以使用帶有@JavaHandler註釋的gremlin來代替使用@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(); 
    } 
} 
0

我不認爲你必須有正確的使用給對文檔的框架爲註釋:

https://github.com/tinkerpop/frames/wiki/Gremlin-Groovy

首先,請注意,這兩個:

@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}") 
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid); 

和:

@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has')") 

返回Iterator,因此不是那麼有用,因爲您需要在getFooEdgeFromUuid()中返回某種形式的List。也許適當的事情,假設你知道一個事實,這個查詢只能始終返回一個邊緣是做:

@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has').next()") 

我說「永遠」,因爲如果沒有這一點,你會得到一個自己否則爲NoSuchElementException。這樣一來,以正確對齊類型,你可以這樣做:

@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid)}") 
Iterable<FooEdge> getFooEdgesFromUuid(@GremlinParam("uuid") String uuid); 

當然,所有可能不行,因爲這句話我在文檔中看到的:

It is possible to make use of a Gremlin path expression as a means of determining vertex adjacency via the GremlinGroovyModule.

換句話說,使用@GremlinGroovy是爲了返回框架頂點(而不是你正在嘗試做的)。如果我上面建議的方法不起作用,那麼使用@JavaHandler的解決方法可能是您的最佳選擇。

+0

我之所以使用hasNext()是因爲過濾器閉包需要一個布爾結果來確定某個特定頂點是否通過。 – cscan

+0

oops - 你是對的 - 我誤解了它 - 對我的回答稍作更新.... –