I am using Neo4j-Spatial with Spring data in a Play!Framework application.
I have a @NodeEntity of type User which I want to store in the database as well as a spatial index for location based queries.
The examples that I have seen create a Node using the GraphDatabaseService:
Node stadiumNode = graphDatabaseService.createNode();
and then add this Node to the spatial index:
Index<Node> index = graphDatabaseService.index().forNodes(indexLayerName, config)`;
stadiumNode.setProperty("wkt", String.format("POINT(%s %s)", lat, lon));
index.add(stadiumNode, "dummyA", "dummyB");
However, the Node does not have a specific type (such as User) associated with it. In order to do that, I have to first create interface UserRepository extends GraphRepository<User>
:
@Autowired
private UserRepository userRepository;
and then add the User nodeEntity to the repository:
User user = new User();
userRepository.save(user);
However, this creates 3 nodes (1 in the spatial index RTree, and 2 in the neo4j graph). What is the correct way of doing this? I just want 2 nodes:
- One node of type User in the neo4j graph
- One node containing location information associated with the above node.