Database Reference
In-Depth Information
Within the
Movie
node entity, the
RelatedToVia
annotation marks the
views
fieldasrepresentative of“allthe
HAS_SEEN
relationships(withanyassociatedproperties)
between this movie and any users who have actually watched it.”
Inbothcasesthe
Viewing
classprovidesawaytoaccesstheextracontextualinformation
abouttherelationship,overandabovethefactthatthesetwoentitiesaremerelyrelated—in
this case, the extra contextual information is the specific rating provided for each viewing.
You may at this stage be wondering why in one case the relationship was modeled with a
Set
(on the
User
) and with an
Iterable
in the other (on the
Movie
). All will be re-
vealed in the next section, so keep reading!
In the next section we'll continue to detail some of the finer points defining different types
of relationships between node entities, including where the rich relationship details are re-
quired to fully understand the context.
9.2.5. Modeling relationships between node entities
Being able to model node and relationship entities with their simple associated properties
in isolation will take you only so far. Models start getting interesting when you're able to
actually connect them to explore the relationships between them, and in this section, we'll
cover how to do that.
The end of the previous section provided a preview of how such a connection could be es-
tablished between the
User
and
Movie
entities through the
Viewing
relationship entity.
You saw how the
HAS_SEEN
relationship between
Users
and
Movies
was modeled as
a physical POJO (the
Viewing
class) and was then referred to from the entities. In that
particular case, a whole separate class (
Viewing
) was used to represent the relationship
in context. But what about other, simpler relationships, such as “John is a friend of Jack”?
Do you also need a dedicated relationship entity class for such cases? You'll be pleased to
know the answer is no—they can be dealt with in a much simpler manner.
Figure 9.5
recaps the relationships between node entities that you're potentially interested
in referencing from the node entities.