java - Neo4J Spring relateTo 函数无法解析

标签 java spring neo4j

给定以下类:

package com.example.model;

import java.util.Collection;
import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.neo4j.helpers.collection.IteratorUtil;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.annotation.RelatedToVia;
import org.springframework.security.core.GrantedAuthority;

@NodeEntity
public class User {
    private static final String SALT = "cewuiqwzie";
    public static final String FRIEND = "FRIEND";
    public static final String RATED = "RATED";
    @Indexed
    String login;
    String name;
    String password;
    String info;
    private Roles[] roles;

    public User() {
    }

    public User(String login, String name, String password, Roles... roles) {
        this.login = login;
        this.name = name;
        this.password = encode(password);
        this.roles = roles;
    }

    private String encode(String password) {
        return "";
        // return new Md5PasswordEncoder().encodePassword(password, SALT);
    }

    @RelatedToVia(elementClass = Rating.class, type = RATED)
    Iterable<Rating> ratings;

    @RelatedTo(elementClass = Movie.class, type = RATED)
    Set<Movie> favorites;

    @RelatedTo(elementClass = User.class, type = FRIEND, direction = Direction.BOTH)
    Set<User> friends;

    public void addFriend(User friend) {
        this.friends.add(friend);
    }

    public Rating rate(Movie movie, int stars, String comment) {
        return relateTo(movie, Rating.class, RATED).rate(stars, comment);
    }

    public Collection<Rating> getRatings() {
        return IteratorUtil.asCollection(ratings);
    }

    @Override
    public String toString() {
        return String.format("%s (%s)", name, login);
    }

    public String getName() {
        return name;
    }

    public Set<User> getFriends() {
        return friends;
    }

    public Roles[] getRole() {
        return roles;
    }

    public String getLogin() {
        return login;
    }

    public String getPassword() {
        return password;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public void updatePassword(String old, String newPass1, String newPass2) {
        if (!password.equals(encode(old)))
            throw new IllegalArgumentException("Existing Password invalid");
        if (!newPass1.equals(newPass2))
            throw new IllegalArgumentException("New Passwords don't match");
        this.password = encode(newPass1);
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isFriend(User other) {
        return other != null && getFriends().contains(other);
    }

    public enum Roles implements GrantedAuthority {
        ROLE_USER, ROLE_ADMIN;

        @Override
        public String getAuthority() {
            return name();
        }
    }
}

我在这里得到一个编译异常:

public Rating rate(Movie movie, int stars, String comment) {
            return relateTo(movie, Rating.class, RATED).rate(stars, comment);
        }

tutorial here 之后.任何有关此功能所在位置的见解都将受到赞赏。

最佳答案

您正在尝试使用高级映射模式。查看reference manual了解更多信息。您需要在 IDE 中设置 AspectJ 支持。方法在编译时被编织到您的实体类中。

关于java - Neo4J Spring relateTo 函数无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15733958/

相关文章:

java - Android Java Bitmap.getPixels 返回仅填充 -1 作为值的数组

java - 无法强制 Spring Web MVC 3.0 框架工作

java - Neo4j Java API - 架构索引范围查找?

docker - 无法通过dockerized Traefik访问dockerized Neo4j Web界面

java - 我可以将 Arrays.fill 与二维数组一起使用吗?如果是这样,我该怎么做?

java - 在Java中创建和访问文件时的默认路径不应该是jar吗?

JAVA jdbc blob?

java - 使现有的 Spring Batch 应用程序在多个节点上运行

java - IntelliJ IDEA 无法解析 spring 导入的文件

java - Neo4J 输入无效 '(' : expected an identifier character, 空格,NodeLabel