Database Reference
In-Depth Information
(modeled by the
referredBy
property ) is an excellent example of this. Note that
this property must be a reference to another node entity.
Basic relationships to zero or more other node entities are modeled with a
Set
,
List
,
Collection
,or
Iterable
class,withthereferencednodeentityasthecollectiontype.
The use of a
Set
,
List
, or
Collection
class signifies that the field is modifiable from
the containing node's perspective; an
Iterable
class indicates this should be treated
as read-only. Based on the contained node entity class type and its annotations, SDN
will be able to work out that your intention is for this field to represent a basic relation-
ship. If, however, you'd like to overwrite any of the defaults inferred, you can add an
@RelatedTo
annotation. The
friends
relationships between users is an example.
Note how in this case we added the
@RelatedTo
annotation with the
type
property to
specify the underlying Neo4j relationship type as
IS_FRIEND_OF
rather than the default
value that SDN would have inferred if it were not there. In the absence of the annotation,
SDN would have used the name of the field,
friends
, as the name to be used for the un-
derlying relationship type property.
Rich
relationships, those represented by an underlying Neo4j relationship with associated
properties, are also modeled with the same
Collection
class as basic relationships. In
this case, however, the type of the contained entity in the collection is a relationship entity
rather than a node entity. To recap, a
relationship entity
represents the underlying Neo4j
relationship along with any associated properties that were also modeled in the entity (see
section 9.2.4
)
.Thisprovidesaneatwaytoaccesstherichinformationontherelationshipit-
self,whilestillbeingabletogettotheentityorentitiesontheotherend.Aswithbasicrela-
tionships, without any annotations, SDN can work out that you're creating such references
based solely on the fact that the type of class contained in the collection has been defined
as a relationship entity.Again, if youwish to override any ofthese relationship defaults as-
sumed by SDN, you can apply the
@RelatedToVia
annotation. As you've already seen,
the
views
fieldreference representingtherelationshipbetweena
User
anda
Movie
is a good example; the additional
stars
rating serves to enhance the information about
the relationship between these two entities. Notice the different
Collection
class used
for the
views
property in the case of the
User
and
Movie
nodes, namely
Set<View-
ing>
and
Iterable<Viewing>
.Thismeansthatthe
views
propertycanbemodified
from the
User
node perspective but not from the
Movie
node. Conceptually, users rate
movies; movies don't apply ratings to users.