【发布时间】:2015-08-20 14:29:29
【问题描述】:
我正在使用 spring boot 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 多个站点的stations.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
所以我基本上对这个错误感到困惑,希望能得到一些帮助。
如果有更好的方法,请告诉我。
总经理
【问题讨论】:
标签: spring neo4j spring-boot spring-data spring-data-neo4j