根据此用户指南,当使用高级映射模式时,对属性和关系的任何访问通常都会向下读取到数据库。这是否意味着不会获取整个对象,只会读取必要的属性?如我错了请纠正我。
我正在使用高级映射模式,这是我的 Maven 设置(仅显示必要的代码):
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-aspects</artifactId>
<version>3.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.6</version>
</dependency>
.........
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.6</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
我的 Spring 配置运行良好,所以我只是跳过它并保存一些地方。
这里有点奇怪,当我访问 User 对象的 lover 属性的 name 属性时,它总是返回 null:
@RelatedTo(type = "loves", direction = Direction.OUTGOING)
private User lover;
系统 println 结果为:
{id=0, theme=null, name=Pamela, password=2663, lover={id=1, name=null}}
添加@Fetch 时:
@RelatedTo(type = "loves", direction = Direction.OUTGOING)
@Fetch
private User lover;
事实证明是正确的:
{id=0, theme=null, name=Pamela, password=2663, lover={id=1, name=Bond}}
有谁知道出了什么问题?谢谢