SDN4不返回嵌套实体

时间:2018-10-12 11:04:51

标签: java spring-data-neo4j

Hello Stack溢出,

我遇到以下问题:

我有以下实体类:

    public class UnknownEntity extends NetworkEntity{
        @Id
        @GeneratedValue(strategy = UuidStrategy.class)
        private String id;

        @Override
        public void setId(String id) {
            this.id = id;
        }

        @Override
        public String getId() {
            return id;
        }
    }


    @NodeEntity
    public class NetworkEntity {

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        @Id
        protected String id;

        public List<NetworkInterfaceEntity> getInterfaces() {
            return interfaces;
        }

        public void setInterfaces(List<NetworkInterfaceEntity> interfaces) {
            this.interfaces = interfaces;
        }

        @Relationship(type = "is_composed_of")
        protected List<NetworkInterfaceEntity> interfaces ;
    }


@NodeEntity
public class NetworkInterfaceEntity {
    public String getInterfaceId() {
        return interfaceId;
    }

    public void setInterfaceId(String interfaceId) {
        this.interfaceId = interfaceId;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getNetmask() {
        return netmask;
    }

    public void setNetmask(String netmask) {
        this.netmask = netmask;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }

    public String getName() {
        return name;
    }

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

    public InterfaceState getState() {
        return state;
    }

    public void setState(InterfaceState state) {
        this.state = state;
    }

    public List<NetworkInterfaceEntity> getSubInterfaces() {
        return subInterfaces;
    }

    public void setSubInterfaces(List<NetworkInterfaceEntity> subInterfaces) {
        this.subInterfaces = subInterfaces;
    }

    public long getBytesSent() {
        return bytesSent;
    }

    public void setBytesSent(long bytesSent) {
        this.bytesSent = bytesSent;
    }

    public long getBytesRecived() {
        return bytesRecived;
    }

    public void setBytesRecived(long bytesRecived) {
        this.bytesRecived = bytesRecived;
    }

    @Id
    private String interfaceId;
    private String ipAddress;
    private String netmask;
    private String macAddress;
    private String name;
    private InterfaceState state;
    @Relationship(type = "is_composed_of")
    private List<NetworkInterfaceEntity> subInterfaces;
    private long bytesSent;
    private long bytesRecived;


}

当我现在尝试使用自定义@Query方法通过Neo4j Crud存储库查询UnknownEntities时,UnknownEntities将不会与必要的NetworkInterfaceObjects嵌套,即使我的查询很难返回这些信息。

public interface UnknownEntityRepository extends CrudRepository<UnknownEntity,String> {
    @Query("MATCH (u:UnknownEntity)-[:is_composed_of]->(i:NetworkInterfaceEntity) WHERE i.ipAddress IN {0} WITH u as unknown MATCH p=(unknown)-[r*0..1]-() RETURN collect(unknown),nodes(p),rels(p)")
    List<UnknownEntity> searchMachinesByIp(List<String> ipAddresses);
}

在这种特殊情况下,NetworkInterfaceEntities不包含更多的subInterfaces,因此我只希望属于UnknownEntity的NetworkInterfaceEntities。但是,当我使用此查询时,我只会得到UnknownEntities,其中NetworkInterfaceList为null。我什至尝试了不同的查询,但无济于事: “ MATCH p =(u:UnknownEntitie)-[:is_composed_of]-(n:NetworkInterfaceEntity)在{0}中的n.ipAddress处返回collect(n),nodes(p),rels(p)”。

我的问题是,如果使用SDN4 Data甚至可以实现我想要的,那我该如何实现呢,因为我的选择是分别查询每个NetworkInterface的数据库,这确实很丑。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

请尝试返回以下完整路径:

varchar

为您服务。如果不是,请尝试命名有问题的对象,即md5对您有用。

您是否正在使用Spring Data Neo4j 4或5?如果您使用的是4,请考虑将升级到5处于受支持的级别。

如果有帮助,请告诉我。