Я начал изучать разработку REST API с использованием Spring и Neo4J. Я не могу понять, как работают репозитории, даже просматривая документацию.
У меня есть узел Airport и связь LINE. В базе данных Neo4J хранятся двусторонние линии между двумя аэропортами. Я хотел бы получить все отношения между всеми аэропортами. Как я могу это сделать? Я попробовал этот запрос. Он возвращает правильное количество экземпляров класса Line, но все атрибуты имеют значение NULL. Что я делаю не так?
Это класс AirportNode:
@Node("Airport")
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class AirportNode implements Serializable {
/**
* The unique identifier for the airport node in Neo4J.
*/
@Id
@GeneratedValue
private Long id;
/**
* The relational database ID corresponding to this airport.
* This links the Neo4j node to its counterpart in a relational database.
*/
@Property("relational_id")
private Long relationalId;
/**
* IATA code of the airport (3-letter code).
* This is a unique identifier for the airport according to the International Air Transport Association standard.
*/
@Property("code")
private String code;
@Property("name")
private String name;
@Property("country")
private String country;
@Property("zone")
private String zone;
@Property("latitude")
private Double latitude;
@Property("longitude")
private Double longitude;
/// Getters, Setters, ctors
}
Это класс Line:
@RelationshipProperties
@Getter
@Setter
public class Line {
/**
* The unique identifier for this relationship in Neo4J.
*/
@Id
@GeneratedValue
private Long id;
/**
* The destination airport that this line connects to.
*/
@TargetNode
private AirportNode destination;
@Property(name="distance")
private Double distance;
@Property(name="relational_id")
private Long relationalId;
// getters, setters, ctors
}
Это LineRepository с запросом:
public interface LineRepository extends Neo4JRepository {
@Query("""
MATCH (origin:Airport)-[r:LINE]->(destination:Airport)
WHERE id(origin) < id(destination)
RETURN r, destination
""")
List findAllLines();
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ing-spring