SDN4 不返回嵌套实体
SDN4 is not returning nested Entities
你好堆栈溢出,
我有以下问题:
我有这些实体 类:
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,即使我的查询 returns 这些也是如此。
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 不包含更多子接口,因此我只想要属于 UnknownEntity 的 NetworkInterfaceEntities。但是当我使用这个查询时,我只得到 NetworkInterfaceList 为空的 UnknownEntities。我什至尝试了不同的查询无济于事,例如:
"MATCH p=(u:UnknownEntitie)-[:is_composed_of]-(n:NetworkInterfaceEntity) WHERE n.ipAddress in {0} RETURN collect(n),nodes(p),rels(p)"。
我的问题是,如果我想要的甚至可以通过 SDN4 数据实现,如果可以,我该如何实现,因为我的替代方法是分别查询每个网络接口的数据库,我认为这真的很难看。
如有任何帮助,我们将不胜感激。
如果像这样返回完整路径,请尝试:
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 p")
List<UnknownEntity> searchMachinesByIp(List<String> ipAddresses);
}
适合你。如果不是,请尝试命名有问题的对象,即 RETURN i as subInterfaces
适合您。
您使用的是 Spring Data Neo4j 4 还是 5?如果您使用的是 4,请考虑升级到 5 以达到受支持的水平。
如果有帮助,请告诉我。
你好堆栈溢出,
我有以下问题:
我有这些实体 类:
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,即使我的查询 returns 这些也是如此。
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 不包含更多子接口,因此我只想要属于 UnknownEntity 的 NetworkInterfaceEntities。但是当我使用这个查询时,我只得到 NetworkInterfaceList 为空的 UnknownEntities。我什至尝试了不同的查询无济于事,例如: "MATCH p=(u:UnknownEntitie)-[:is_composed_of]-(n:NetworkInterfaceEntity) WHERE n.ipAddress in {0} RETURN collect(n),nodes(p),rels(p)"。
我的问题是,如果我想要的甚至可以通过 SDN4 数据实现,如果可以,我该如何实现,因为我的替代方法是分别查询每个网络接口的数据库,我认为这真的很难看。
如有任何帮助,我们将不胜感激。
如果像这样返回完整路径,请尝试:
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 p")
List<UnknownEntity> searchMachinesByIp(List<String> ipAddresses);
}
适合你。如果不是,请尝试命名有问题的对象,即 RETURN i as subInterfaces
适合您。
您使用的是 Spring Data Neo4j 4 还是 5?如果您使用的是 4,请考虑升级到 5 以达到受支持的水平。
如果有帮助,请告诉我。