Database Reference
In-Depth Information
null
at this point.
Whenyouwanttoloadthefullentity,youcanmakeuseofthe
Neo4JTemplate fetch
method, shown in the following extension snippet, which would follow directly after the
code in
listing 9.11
:
template.fetch(loadedSally.getFriends());
assertEquals( "John", firstFriendOfSusan.getName());
Alternatively, if you want SDN to eagerly instantiate the entities at loading time, you can
annotate the appropriate property with
@Fetch
, as in the following snippet:
...
@Fetch
@RelatedTo(type = "IS_FRIEND_OF", direction = Direction.BOTH)
Set<User> friends;
...
You've now had a brief overview of the simple mapping mode, which can probably be
summed up with the phrase “Simple, yet powerful, but potentially memory-hungry too!”
Next up is advanced mapping!
Mandatory @GraphId property should be defined as a Long
Simple mapping mandates that domain modelers provide a property annotated with
@GraphId
tostoretheassociatednodeorrelationshipID,providingthelibrarywithalink
to the underlying node or relationship backing it. The value will be
null
when the entity
has yet to be persisted to Neo4j (typically when you use the
new
keyword to create your
entity), but once it has been saved at least once, it will be populated to reflect the underly-
ing node or relationship it's connected to in the graph.
Words of caution here. Make sure you define this property as the
Long
data type and not
asthe
long
primitive.Thewrapperclassallowsfora
null
tobespecified,indicatingthat
theentityhasyettobepersistedintothegraph.Ifyoudefinethisfieldasaprimitive
long
,
this will mean that its default value will always be
0
. Zero, however could represent a real
node ID (prior to Neo4j 2.0, the reference node present in all graph databases was always