Spring-Data_Neo4j高级映射不起作用

时间:2015-07-29 01:34:04

标签: aspectj spring-data-neo4j aspectj-maven-plugin

根据这个User Guide,当使用高级映射模式时,对属性和关系的任何访问通常都会读到数据库。这是否意味着整个对象不会被获取,只会读取必要的属性?如果我错了,请纠正我。

我正在使用高级映射模式,这是我的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}}

任何人都知道出了什么问题? THX

0 个答案:

没有答案