Database Reference
In-Depth Information
If you'd like to access the node entities on either side of this relationship, you'll need
to provide a field for each of these and annotate them with @StartNode
and
@EndNode . For the Viewing class example, the User node entity starts (has the
outgoing) relationship to the ending Movie entity.
In terms of what's required to model a Neo4j relationship, that's it. There is, however, gen-
erally not much point in defining relationship entity classes in isolation. They're almost
always referred to through one or more fields on associated node entities. In section 9.2.5
we'll go into detail about how node entities can refer to other node entities through simple
references, but also through POJO-modeled relationships. To provide the full context for
this example, the following listing provides a sneak preview of how the User node entity,
as well as the Movie node entity, refer to the Viewing relationship entity class through
their views field.
Listing 9.4. User and Movie node entity snippets
Within the User node entity, the RelatedToVia annotation on the views field
essentially reads as “all the HAS_SEEN relationships (with any associated properties)
between this user and any movies the user has watched.” (The HAS_SEEN relationship
type is inferred because that is what's defined in the type property on the annotation of
the Viewing class itself.) The Viewing class represents the full context of the relation-
ship between these two entities including the rating field. Note that in this case (unlike
the Movie classdetailednext)youdon'texplicitlyspecify direction = Direction
.OUTGOING within the annotation because this is the default.
Search WWH ::




Custom Search