1

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);
 }
}
7
  • Either the package to scan for packages has a typo or the Actor class is another package. It runs on my machine without any problem (also with OGM 3.1.0). Commented Feb 14, 2018 at 8:19
  • No, you can see the qualified name of Actor class in question title, it's clearly mentioned there "com.my.domain.Actor" and that's what confusing me. Even though the package name is correct, am getting this exception.
    – Anil Kumar
    Commented Feb 14, 2018 at 8:55
  • I assume that your code is all in one application, right? So there is no 'domain project' or something like this(?) Because your sample is also started from within a simple main method there cannot be any problem with class loading. Commented Feb 14, 2018 at 9:00
  • No, entities are also in same project (but in different 'package') as Main class.
    – Anil Kumar
    Commented Feb 14, 2018 at 9:06
  • 1
    @Vinay Nagraj actually I was developing an Intellij IDE plugin which requires neo4j database.To store the POJO in neo4j using annotations, it requires a default class loader.But in my case, Intellij uses it's own class loader and it can't work with neo4j annotations as it's not possible to create objects of a class from library.
    – Anil Kumar
    Commented Apr 30, 2018 at 10:04

2 Answers 2

2

Check your package scanning in SessionFactory eg. new SessionFactory(configuration, "com.my.domain");

If declared package is not your entity package then this error also occurs

1

Try to check if bean for the class actor is loaded in the spring context properly. If it is not there in the context at run time due to wrong configuration (for example: @EntityScan is not defined with proper path), this exception can occur.

Not the answer you're looking for? Browse other questions tagged or ask your own question.