0

I am struggling how to convert this example: https://spring.io/guides/gs/accessing-data-neo4j/ to work on new version of Spring Data. I obviously change imports for Person.java to org.neo4j.ogm.*. I have added:

  @Bean 
  public SessionFactory getSessionFactory()
  {
    logger.info("ApplicationConfig::getSessionFactory()");
    return new SessionFactory("hello");
  }

  @Bean
  public Session getSession() throws Exception {
    logger.info("Initialising Neo4jSession");
        SessionFactory sessionFactory = getSessionFactory();
        Assert.notNull(sessionFactory, "You must provide a SessionFactory instance in your Spring configuration classes");
        return sessionFactory.openSession();
  }

to Application.java file. But I don't know how to change method:

@Bean CommandLineRunner demo(PersonRepository personRepository, GraphDatabase graphDatabase)

to work. I have tried move code from this method to constructor of its class, but I need to have PersonRepository.

Marcin
  • 422
  • 6
  • 17

1 Answers1

4

The GraphDatabaseService should not be used to manage the transaction, if instead you inject a org.neo4j.ogm.session.Session, you will use session.beginTransaction()

AFAIK, the PersonRepository will be injected as it was in SDN 3.

Here are two more articles introducing SDN 4.1-

http://graphaware.com/neo4j/2015/12/15/the-essence-of-spring-data-neo4j-4.html http://graphaware.com/neo4j/2016/02/24/upgrading-spring-data-neo4j-4-1.html

Luanne
  • 19,145
  • 1
  • 39
  • 51