使用Spring引导1.2.3.RELEAE和spring-data-neo4j 3.2.2.RELEASE使用Neo4J 2.1.5。
我正在尝试建立一个通过“CONNECTED_TO”关系连接到其他电台的电台图。这种关系具有“距离”作为财产。后来我们计划在图上做dijkstra的算法。但无论如何......这就是我们所拥有的:
@NodeEntity
@TypeAlias("Station")
public class Station {
@GraphId
private Long id;
@Indexed
public String name;
@Indexed(unique = true)
public String tlc;
public double gps_x;
public double gps_y;
@RelatedTo(type = "CONNECTED_TO", direction = OUTGOING)
public Set<Station> connectedTo = new HashSet<>();
@Fetch
@RelatedToVia(type = "CONNECTED_TO", direction = OUTGOING)
public Set<ConnectedTo> connections = new HashSet<>();
// getter + setters
}
@RelationshipEntity(type = "CONNECTED_TO")
public class ConnectedTo {
@GraphId
private Long id;
@Fetch
@StartNode
private Station fromStation;
@Fetch
@EndNode
private Station toStation;
private double distance;
// getter + setters
}
并且有一个带有2K加站的station.csv ......这是一个示例:
name,tlc,gps_y,gps_x
Alexandra Palace,AAP,-0.120235219,51.59792231
Achanalt,AAT,-4.913851155,57.60959445
Aberdare,ABA,-3.443083402,51.71505622
Altnabreac,ABC,-3.706280166,58.38814697
然后对于关系船(5K加)我们有station_connections.csv ..这里有一个样本:
name,from_tlc,to_tlc,distance
Alexandra Palace,AAP,BOP,0.7
Alexandra Palace,AAP,HRN,0.9
Alexandra Palace,AAP,NSG,1.5
Achanalt,AAT,ACN,6.5
Achanalt,AAT,LCC,4.2
Aberdare,ABA,CMH,0.8
Altnabreac,ABC,FRS,8.1
Altnabreac,ABC,SCT,9.1
然后我有一个导入服务来导入CSV
首先,我从stations.csv导入电台。这很好用。这是导入它的代码:
@Transactional
public void importStations(CsvReader stationsFile) throws IOException {
// id,terminalName,name,installed,locked,temporary,lat,lng
while (stationsFile.readRecord()) {
Station station = new Station()
.setName(stationsFile.get("name").toUpperCase())
.setTlc(stationsFile.get("tlc").toUpperCase())
.setGps_y(asDouble(stationsFile.get("gps_y")))
.setGps_x(asDouble(stationsFile.get("gps_x")));
stationRepository.save(station);
}
}
其次,我想从station_connections.csv导入站连接。使用以下代码:
@Transactional
public void importConnections(CsvReader stationsFile) throws IOException {
// name,from_tlc,to_tlc,distance
while (stationsFile.readRecord()) {
String from_tlc = stationsFile.get("from_tlc").toUpperCase();
String to_tlc = stationsFile.get("to_tlc").toUpperCase();
String distance = stationsFile.get("distance");
Station fromStation = stationRepository.findByTlc(from_tlc);
Station toStation = stationRepository.findByTlc(to_tlc);
if (fromStation != null && toStation != null) {
// need to do this get the connected stations...!!!
template.fetch(fromStation.getConnectedTo());
template.fetch(toStation.getConnectedTo());
fromStation.addStation(toStation);
template.save(fromStation);
System.out.println(from_tlc + " connected to: " + to_tlc);
}
}
}
因此,当它尝试导入连接时,我收到以下错误:RELATIONSHIP[4434] has no property with propertyKey="__type__".
Exception in thread "main" org.neo4j.graphdb.NotFoundException: RELATIONSHIP[4434] has no property with propertyKey="__type__".
at org.neo4j.kernel.impl.core.RelationshipProxy.getProperty(RelationshipProxy.java:195)
at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexBasedTypeRepresentationStrategy.readAliasFrom(AbstractIndexBasedTypeRepresentationStrategy.java:126)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:36)
at
所以我基本上对这个错误感到困惑,并希望得到一些帮助。
如果有更好的方法,请告诉我。
GM
答案 0 :(得分:0)
你能检查id为4434的关系吗?如果它确实没有这个属性,那么它是什么样的关系。
这意味着SDN无法加载映射到Java类型的关系,因为某种类型信息没有存储在它上面。
您可以在template.postEntityCreation(rel, ConnectedTo.class);