2

I am using Neo4j OGM 2.0.4 driver with Java (embedded driver). When I do save(item) on session everything looks all right. Hovewer when I want to load items from database I get this exception:

16:01:23.182 [main] INFO  org.neo4j.ogm.service.DriverService - Using driver: org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
16:01:24.768 [main] DEBUG org.neo4j.ogm.service.Components - Setting driver to: org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
16:01:24.782 [main] WARN  org.neo4j.ogm.session.Neo4jSession - Thread 1: neo4jCMS.entity.Author is not an instance of a persistable class
16:01:24.782 [main] WARN  org.neo4j.ogm.session.Neo4jSession - Thread 1: neo4jCMS.entity.Author is not an instance of a persistable class
Saved
Exception in thread "main" java.lang.NullPointerException
    at org.neo4j.ogm.MetaData.entityType(MetaData.java:280)
    at org.neo4j.ogm.session.Neo4jSession.entityType(Neo4jSession.java:486)
    at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.loadAll(LoadByTypeDelegate.java:60)
    at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.loadAll(LoadByTypeDelegate.java:108)
    at org.neo4j.ogm.session.Neo4jSession.loadAll(Neo4jSession.java:152)
    at neo4jCMS.TestSite.run(TestSite.java:35)
    at neo4jCMS.Application.main(Application.java:20)

While executing:

Author author1 = new Author("Author no 1");
Author author2 = new Author("Author no 2");

session.save(author1);
session.save(author2);
System.out.println("Saved");

Iterable<Author> authors = session.loadAll(Author.class);
for (Author author : authors)
{
  System.out.println("Author: " + author.getName());
}

My node class is:

@NodeEntity
public class Author
{
  @GraphId
  private Long id;
  private String _name;

  public Author() { _name = "";}

  public Author(String name)
  {
    _name = name;
  }

  public String getName()
  {
    return _name;
  }
}
2
  • Can you confirm that authors return from session.loadAll(Author.class); is not null - your error points to a NullPointerException. Aug 29, 2016 at 21:35
  • @ishmaelMakitla The stack trace shows that the exception occurs while inside that method, not after it returns.
    – user207421
    Aug 29, 2016 at 23:03

2 Answers 2

2

First of all you will need to add a no-arg constructor to your Author class in order for the OGM to create objects.

If that does not solve it try rerunning the loadAll code segment again. I have seen the odd Exception on first execution. I thought this was fixed but maybe it's only in 2.0.5-SNAPSHOT.

3
  • I have added constructor to NodeEntity but it still failing.
    – Marcin
    Sep 2, 2016 at 14:03
  • I turn on input from logger and I added it to the question.
    – Marcin
    Sep 2, 2016 at 14:07
  • I have tryied to switch to 2.0.5-SNAPSHOT Maven cannot download it.
    – Marcin
    Sep 2, 2016 at 14:08
0

The issue was in configuration. new SessionFactory() was without argument "myProject.subDirectory". After adding that it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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