neo4j :: Getting java.lang.IllegalArgumentException: Class class com.my.domain.Actor is not a valid entity class. Please check the entity mapping

Anil Kumar Source

I was trying to learn Neo4j-OGM(Version:3.1.0).But I stucked with this Exception.Even tried with older versions but no use.And googled for help but couldn't find anything.Neo4j is the only choice for my project.I don't find anything wrong with my code. Can anyone help me with this? Thanks :) Here is my code..Sorry for this lengthy question.

@NodeEntity(label="Film")
public class Movie {
    @GraphId
    Long id;
    @Property(name="title")
    private String name;
    public Movie(String name){
        this.name=name;
    }
    public Movie(){}       
}

@NodeEntity
public class Actor  {
    @Id
    @GeneratedValue
    private Long id;
    @Property(name="name")
    private String fullName;

    @Relationship(type="ACTED_IN", direction=Relationship.OUTGOING)
    private List<Role> filmography;

    public Actor(String name){
        this.fullName=name;
        this.filmography=new ArrayList<>();
    }
    public Actor(){}
    public void addRole(Role r){
        this.filmography.add(r);
    }        
}

@RelationshipEntity(type="ACTED_IN")
public class Role {
    @Id @GeneratedValue  private Long relationshipId;
    @Property            private String title;
    @StartNode           private Actor actor;
    @EndNode             private Movie movie;
    public Role(){}
    public Role(String title,Actor actor,Movie movie){
        this.actor=actor;
        this.title=title;
        this.movie=movie;
    }
}
public class Main{
   public static void main(String[] a){
        Movie m1=new Movie("M1");
        Actor a1=new Actor("A1");
        Actor a2=new Actor("A2");
        Movie m2=new Movie("M2");
        Role r1=new Role("R1",a1,m1);
        Role r2=new Role("R2",a2,m1);
        Role r3=new Role("R3",a2,m2);
        a1.addRole(r1);
        a2.addRole(r2);
        a2.addRole(r3);
        Configuration configuration = new Configuration.Builder()
            .uri("bolt://localhost")
            .credentials("neo4j", "admin")
            .build();
        SessionFactory sessionFactory = new SessionFactory(configuration, "com.my.domain");
        Session session=sessionFactory.openSession();
        session.beginTransaction();
        session.save(a1);
        session.save(a2);
 }
}
javaneo4jneo4j-ogm

Answers

comments powered by Disqus