首先进行一些基本的修改以创建域模型。
我让泰坦跑了起来,添加了众神的头像,然后使用格蕾姆林成功地穿越了它。

但是当我尝试创建一个FramedGraph时,我得到以下堆栈跟踪:

java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at peapod.internal.runtime.FramerRegistry.lambda$register$1(FramerRegistry.java:47)
at java.lang.Iterable.forEach(Iterable.java:75)
at peapod.internal.runtime.FramerRegistry.register(FramerRegistry.java:45)
at peapod.FramedGraph.<init>(FramedGraph.java:73)
at my.domain.model.Main.main(Main.java:28)
Caused by: java.lang.RuntimeException: Uncompilable source code - my.domain.model.vertices.Person$Impl is not abstract and does not override abstract method start() in peapod.FramedVertexTraversal
at my.domain.model.vertices.Person$Impl$PersonFramer.<clinit>(Person$Impl.java:14)
... 10 more


这是我的脚本:

public static void main(String[] args) {
    System.out.println("--- Creating Titan client ---");
    TitanGraph graph = TitanFactory.open("path/to/titan-1.0.0-hadoop1/conf/titan-cassandra-es.properties");
    //GraphTraversalSource gremlin = graph.traversal();
    System.out.println("--- Creating FramedGraph ---");
    try {
        FramedGraph g = new FramedGraph(graph, Package.getPackage("my.domain.model"));

        //GraphOfTheGodsFactory.load(graph);
        //Vertex saturn = gremlin.V().has("name", "saturn").next();
        //System.out.println(saturn.value("name"));
        System.out.println("--- Creating Person Vertex and adding it to the graph ---");
        Person person = g.addVertex(Person.class);
        System.out.println("--- Setting its name ---");
        person.setName("alice");

        System.out.println("--- Retriving all Persons with name ---");
        List<Person> persons = g.V(Person.class).has("name", "alice").toList();

        assert 1 == persons.size() : "More than one Person vertex found.";

        g.close();
    } catch (ExceptionInInitializerError e) {
        e.printStackTrace();
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    graph.close();
}


我的抽象Person类:

package my.domain.model.vertices;

import peapod.annotations.Vertex;

@Vertex
public abstract class Person{
  public abstract String getName();
  public abstract void setName(String name);
}


我正在使用Titan 1.0.0 Hadoop1,可能是版本问题,因为peapod使用Tinkerpop 3.0.0.M9-incubating,而titan似乎使用Tinkerpop 3.0.1-incubating

最佳答案

来自Peapod的Willem。我测试了你的课。

Peapod需要Java 8,并使用在接口类中定义的默认方法。确保与Java 8兼容。

将此添加到您的Maven pom.xml文件

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

09-30 16:50