Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException: Employee$ByteBuddy$Yxytgyif cannot be cast to com.syncleus.ferma.AbstractElementFrame #12

Closed
wsalembi opened this issue Jan 2, 2017 · 5 comments

Comments

@wsalembi
Copy link
Contributor

wsalembi commented Jan 2, 2017

A basic vertex creation in Ferma 3.0.2 generates a ClassCastException:

java.lang.ClassCastException: com.syncleus.ferma.annotations.FermaTest$Employee$ByteBuddy$Yxytgyif cannot be cast to com.syncleus.ferma.AbstractElementFrame

	at com.syncleus.ferma.DelegatingFramedGraph.frameElement(DelegatingFramedGraph.java:243)
	at com.syncleus.ferma.DelegatingFramedGraph.frameNewElement(DelegatingFramedGraph.java:249)
	at com.syncleus.ferma.DelegatingFramedGraph.addFramedVertex(DelegatingFramedGraph.java:313)
	at com.syncleus.ferma.DelegatingFramedGraph.addFramedVertex(DelegatingFramedGraph.java:319)
	at com.syncleus.ferma.annotations.FermaTest.testCreation(FermaTest.java:54)

This is the test class. The cause is not the inner class because it doesn't work as seperate class either.

public class FermaTest {

    public static abstract class Employee implements VertexFrame {
        @Property("name")
        public abstract String getName();

        @Property("name")
        public abstract void setName(String name);

    }

    @Test
    public void testCreation() {
        Set<Class<?>> types = new HashSet<>(Arrays.asList(new Class<?>[]{Employee.class}));
        Graph g = TinkerGraph.open();

        //implies annotated mode
        FramedGraph fg = new DelegatingFramedGraph(g, true, types);

        Employee e1 = fg.addFramedVertex(Employee.class);
        e1.setName("Jeff");
    }
}
@freemo
Copy link
Member

freemo commented Jan 2, 2017

This is because your Frame is a class but implements the interface VertexFrame. That is not allowed. You have two ways in which you can resolve this:

  1. Make your Frame an interface instead of a class.
public class FermaTest {

    public interface Employee implements VertexFrame {
        @Property("name")
        String getName();

        @Property("name")
        void setName(String name);
    }

    @Test
    public void testCreation() {
        Set<Class<?>> types = new HashSet<>(Arrays.asList(new Class<?>[]{Employee.class}));
        Graph g = TinkerGraph.open();

        //implies annotated mode
        FramedGraph fg = new DelegatingFramedGraph(g, true, types);

        Employee e1 = fg.addFramedVertex(Employee.class);
        e1.setName("Jeff");
    }
}
  1. extend from AbstractVertexFrame instead of the VertexFrame interface.
public class FermaTest {

    public static abstract class Employee implements AbstractVertexFrame {
        @Property("name")
        public abstract String getName();

        @Property("name")
        public abstract void setName(String name);

    }

    @Test
    public void testCreation() {
        Set<Class<?>> types = new HashSet<>(Arrays.asList(new Class<?>[]{Employee.class}));
        Graph g = TinkerGraph.open();

        //implies annotated mode
        FramedGraph fg = new DelegatingFramedGraph(g, true, types);

        Employee e1 = fg.addFramedVertex(Employee.class);
        e1.setName("Jeff");
    }
}

Both examples above work. I am going to close this issue since it doesnt represent a bug or feature request. However please feel free to continue to comment on it or make any suggestions. I will continue to monitor this issue and respond.

@wsalembi
Copy link
Contributor Author

wsalembi commented Jan 2, 2017

I just followed your documentation and replaced extends by implements because it didn't compile

public abstract class Person extends VertexFrame {
  @Property("name")
  public abstract String getName();

@freemo
Copy link
Member

freemo commented Jan 2, 2017

Where in the documentation did you find that? I will update it.

@wsalembi
Copy link
Contributor Author

wsalembi commented Jan 2, 2017

@freemo
Copy link
Member

freemo commented Jan 2, 2017

@wsalembi Thank you I just fixed this in the readme. Please let me know if you have any problems with any of the other documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants