Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-07-2019 05:45 PM
Hello Guys,
Recently started using Neo4j for my final year project, ran in to a little problem while doing so. I'm maintining a Beacon network where there is only one Node Entity and many relationships between them. I want to know that Am I doing this right. When I queried and Relationship , it did not work. Link to the question is below. Help is greatly appreciated.
Solved! Go to Solution.
08-07-2019 06:03 PM
08-07-2019 05:49 PM
Do you literally have MACs like f:f:f:f
, or were you expecting f
to be replaced, somehow?
08-07-2019 05:52 PM
Thanks for replying. I was going to replace them in the future, but for testing purposes , I created the database like this,
{
"description": "blah_blah",
"location": "stair1",
"MAC": "b:b:b:b"
}
08-07-2019 05:56 PM
Oh it seems I pasted the wrong code in to StackOverflow, In this case c has a different MAC. (e.g - "r:r:r:r"). { changed it in the original post, thanks for pointing it out 🙂 )
When I queried in the Neo4j browser , it returns the Relationship correctly,
{
"angle": 180,
"cost": 4
}
But it seems I could not retrieve that data with my current class structure.
08-07-2019 06:03 PM
Does it make any difference if you return *
?
08-07-2019 06:10 PM
Yes then the API returns this,
{
"angle": 180,
"cost": 4,
"startBeacon": {
"description": "blah_blah",
"location": "junction1",
"mac": "f:f:f:f"
},
"endBeacon": {
"description": "rsad",
"location": "junction2",
"mac": "r:r:r:r"
}
}
This kind of result is more than enough for me , thank you for pointing it out. Can I know the issue with the previous method ?
08-07-2019 06:14 PM
When you run a query in the Neo4j browser, it is "autocompleting" it for you, meaning it expands the returned entity. In this case, you were returning only the relationship between Beacons. The *
ensures the object graph mapper (OGM) sees the entire path, not just the connection. I'm not sure if this is the only way to accomplish this, but this has been successful for me.
08-07-2019 06:19 PM
Understood , thank you very much. Is that the normal way to retrieve a relationship in Neo4j ? I saw some posts about using @QueryResult class as well.
08-07-2019 06:27 PM
I think the @QueryResult is kind of a way to hold an interim result, a DTO you'd use when you want to return not just a object-mapped entity, but also some kind of calculated data (or other entities).
If you have very complex queries with lots of transient variables in play, it is most efficient to only return the ones you need - that's a case you might reconsider the catch-all *
. In this example, you could return a, b, c
and have the same result.
If you want to go deeper, you can capture a property on the relationship, by defining e.g.:
@RelationshipEntity(type = "ADJACENT")
data class ThisEntityToThatEntity(@Id @GeneratedValue var id: Long? = null,
@Property(name = "myProp") var myProp: String? = null,
@StartNode var e1: ThisEntity? = null,
@EndNode var e2: ThatEntity? = null)
And
@Relationship(type = "ADJACENT")
private List< ThisEntityToThatEntity > adjacentList = new ArrayList<>();
08-07-2019 06:31 PM
Understood, thank you for taking your time to reply , really appreciate it. Finally can you tell me some good resources to refer other than the official docs ? Like example projects and as such ? Because I had a hard time finding resources other than the docs.
08-07-2019 06:38 PM
It can be tough, I use this forum pretty frequently. The primary docs tell much of the story, but don't forget to check out the SDN docs. If you cannot get a question answered, don't hesitate to @mention someone you can tell from other questions is familiar with a certain topic.
08-07-2019 06:42 PM
Will do . Thanks again man.
08-07-2019 07:16 PM
Glad I could help, Ravindu.
Could you mark my third response as the solution, and also on SO?
08-07-2019 07:25 PM
With pleasure
08-07-2019 05:54 PM
Understood. Well, that query uses f:f:f:f
for matching both b AND c, so unless that node is ADJACENT
to itself, you wouldn't match.
All the sessions of the conference are now available online