如何使用Java中的session.load加载相关实体或关系数据

时间:2016-02-10 00:21:11

标签: java neo4j neo4j-ogm

使用neo4j-ogm,我写了以下代码: 配置:

@Configuration
@EnableNeo4jRepositories(basePackages="com.neo4j.demo.repositories")
@EnableTransactionManagement
@ComponentScan("com.neo4j.demo")
public class Neo4jApplication extends Neo4jConfiguration{
  @Bean
  public SessionFactory getSessionFactory(){
     return new SessionFactory("com.neo4j.demo.domain");
  }
  @Bean 
  public Neo4jServer neo4jServer(){
     return new        RemoteServer("http://username:password@localhost:7474","neo4j","neo4jhello");  
  }
  @Bean 
  @Scope(value="session",proxyMode=ScopedProxyMode.TARGET_CLASS)
  public Session getSession() throw Exception{
     return super.getSession();
  }
}

NodeEntities:

@NodeEntity
public class Message {
  @GraphId
   Long nodeId;
  @Index(unique=true)
   String id;
   Person author;
  @Relationship(type="LISTENER")
  List<Person>  listeners;
  //getters and setters  
} 
@NodeEntity
public class Person{
  @GraphId
  Long nodeId;
  @Index(unique=true)
  String id;
  String name;
  //getters and setters
}

当我使用session.save来保存Message的新实例时,它运行良好。保存所有相关实体。但session.load看起来效果不好

List<Message> messages = session.loadAll(Message.class,N)

其中N是[-1,3],结果是相同的。作者,侦听器等属性为null。为什么呢?

0 个答案:

没有答案